Jumping Issues

Blitz3D Forums/Blitz3D Beginners Area/Jumping Issues

Captain Wicker (crazy hillbilly)(Posted 2011) [#1]
Hi,
I have been trying to get the Jump() function to move the player up and then back when the spacekey has been hit. Could someone please tell me what I am not doing right?


Last edited 2011


Yasha(Posted 2011) [#2]
Well for a start you have a syntax error - "After" is for navigating type lists, not directing program flow, and has no place in this code.

At the moment all you're doing is directly moving the player upon hitting space. For jumping to make sense, you're first going to need a basic concept of friction, gravity, or both. The easiest way to combine all three of these is with a little something called Verlet integration. Don't worry, it's not as complicated as that page makes it look.

Essentially, you need to store two values alongside your jumping entity: its current Y position, and its old Y position in the previous frame. You'll also want a gravitational constant - what this is will depend on your preference, and how the game feels.

Each frame, you will need to first update the entity's Y position variables, and then set its Y position to the "current Y" variable. You can do this as follows:

- store the current Y value in a temp variable
- set the current Y variable to currentY + (currentY - previousY) - GRAVITY
- update the previous Y variable with the stored value in the temp variable
- after you've done your input-based movement, use "PositionEntity sphere, EntityX(sphere), currentY, EntityZ(sphere)" to update its Y position without interfering with the other dimensions

When the player presses the jump key, just add a vertical force constant (again, depends on how the game plays, but it should actually be quite small) to currentY.

This simple formula is, surprisingly, actually enough to create natural-looking curved jumps.

However, because gravity is also being applied every frame, unless you either have collision applied against the floor, or a hard lower limit (e.g. If currentY < 0 Then currentY = 0), characters using this method will fall through the floor.


Captain Wicker (crazy hillbilly)(Posted 2011) [#3]
Oops! That 'After' statement was a typo! Sorry bout that... :(

I also have a problem with my cursor. how can I get my '.png' cursor file to appear upon the screen?