Side Scroller

Blitz3D Forums/Blitz3D Beginners Area/Side Scroller

Kirkkaf13(Posted 2010) [#1]
Hi,

I have had a few problems trying to create a basic sidescroller game, first one, what is the best way to stop my character falling through the floors? I also need to make some sort of gravity on it so when the player jumps he falls back down until he hits the floor again, I made an attempt at doing this but it got messy and I am not quite sure if my way was the best way as I came across a few problems.

I made a gravity function;

playery = playery + 1


something like that, which makes the character move down the y axis.

I then made a image collision between player and floor which basicly if collide gravity is off until jump key is pressed. This is where the problem started because gravity function was active again it caused my player to not jump.

Sorry is this seems confusing I couldn't really explain things but has anyone got a more logical way of doing things.

OneHitWonder


jfk EO-11110(Posted 2010) [#2]
I would suggest to use 2 Forces: Up and Down. Down is the gravity, that is always there. Up is only there if the player jumps. It starts with a high value, but then the upforce decreases, eg:

downforce#=0.25
while game

if jumpKeyHit
upforce#=2.0
endif

playery#=playery+upforce
playery#=playery-downforce

upforce=upforce*0.9 ; decreaseing up force (if any)
...

So, right after the jump keyhit, the jump goes high quickly, then becomes slower ans falls down again. You may have to find a good relation between up and down force. Down force aka Gravity may also be smoothed, so th eplayer will reach max falling speed only after a certain number of frames in freefall.

Hope this helps.


Kirkkaf13(Posted 2010) [#3]
@jkf EO- 11110

This is great, helps alot now I just need to think how I can put this together, i'm sure after alittle thought I will manage to get this working.

Is the image collision the best way to stop the player falling through the floor?

OneHitWonder


jfk EO-11110(Posted 2010) [#4]
It is one way. Depends on the way the entire game engine works. I think it's not bad and offers some interesting flexibility. Didn't write many Sidescrollers lately, so maybe some other people know more about it.