Curved jump

BlitzMax Forums/BlitzMax Beginners Area/Curved jump

Arry(Posted 2007) [#1]
Hi all,

Before I start I'd just like to say I've searched the forums extensively and played pretty much all day yesterday with some code examples, but am having no luck.

My problem is pretty simple in essence... I need to make a sprite jump in a normal curved arc, as per say manic miner, jet set willy etc.
I obivously know my starting position and the end position will be start+ whatever. The Y co-ordinates start and finish will always be the same.

The problem here is that my maths simply isn't good enough (or it was too long ago!) to pick out the bits I need from the various code examples I have and adapt to my code, which is simply press a button and jump!

I'm not after someone writing it, I'll never learn that way, just maybe some pointers as to what I should be searching for, or where to get started.

Cheers.


QuietBloke(Posted 2007) [#2]
heres a simple way to do it.

have your sprite have a yVelocity. When the player hits the jump button set the yVelocity to something ( eg. -2 ).
On Every update frame :
1. Add the yVelocity to the yPosition if the sprite.
2. Then add something like .1 to the yVelocity
3. If the player collides with the ground then set the yVelocity to zero.
4. If the yVelocity > 2 then set it to 2. This will prevent the player from falling really fast when it is a long drop.

Try something like that and you'll find when you hit jump the player will move up then gradually slow down and then fall back down.

You might then add more code to prevent the player jumping in the middle of a jump.

You can say for example set a flag to say the player is jumping when the player hits the jump button. When the players hit jump again you can then check the flag and dont allow the jump. Unless of course you want to allow the player to jump again. When the player collides with the ground reset the jumping flag.

You might even add some more code so that you first check when the player presses the jump button and set a flag to say the player is about to jump. You then time how long he/she keeps it pressed ( by updating a counter each update frame). Then when they let go you can use the counter to decide how high the player will jump ( the bigger the yVelocity the higher the jump will be ).

Not sure how detailed an explanation you wanted.
Hope that helps.


Big&(Posted 2007) [#3]
If you are after a Manic Miner example:

http://www.blitzbasic.com/codearcs/codearcs.php?code=823

Its just a table of Y data.
Hope this helps.


Arry(Posted 2007) [#4]
Brilliant! Absolutely brilliant! Thanks to you both, much appreciated. No need for all the SIN/COS stuff afterall!

* project back on track *


Grey Alien(Posted 2007) [#5]
Also when you detect the player has collide with the ground, they might be partway into it (if Y velocity>1) so you might need to move the player back up a few pixels to make them exactly touch the ground.

You might want to consider making them hit their head on stuff too.

A platform game can actually be pretty complex when you get into the details. Try adding slopes ;-)