Page 1 of 1
Soooo.....platform jumping?
Posted: Thu Oct 27, 2011 10:25 am
by Benni88
I've searched the forum for posts about jumping and I saw that there were a number of them already. All of them required some sort of velocity or direction in order to function though.
The project i'm working on at the moment is my first and the movements that i've done so far are very rudimentary, so I'm not really sure how to adapt it to add velocities or gravity.
Is it possible to create a jumping motion using the "up" key while still allowing forawrds and backwards movement without rewriting my movement script? Something that allows the player to move 50 pixels or so on the Y-axis while still travelling along the X with the "left" and "right" keys?
Any pointers?
Re: Soooo.....platform jumping?
Posted: Thu Oct 27, 2011 11:16 am
by kikito
Benni88 wrote:Is it possible to create a jumping motion using the "up" key while still allowing forawrds and backwards movement without rewriting my movement script?
No. Your movement script is just not flexible enough.
You will need some sort of velocity control (at the very least) if you want to do movement at all in Löve. A good place to start is the "dt" parameter in
love.update - you can read about it
here.
Re: Soooo.....platform jumping?
Posted: Thu Oct 27, 2011 11:33 am
by Benni88
Cheers, I'll have a go at it and come back if i get stuck.
Re: Soooo.....platform jumping?
Posted: Thu Oct 27, 2011 11:33 am
by ivan
Benni88 wrote:I've searched the forum for posts about jumping and I saw that there were a number of them already. All of them required some sort of velocity or direction in order to function though.
The project i'm working on at the moment is my first and the movements that i've done so far are very rudimentary, so I'm not really sure how to adapt it to add velocities or gravity.
Is it possible to create a jumping motion using the "up" key while still allowing forawrds and backwards movement without rewriting my movement script? Something that allows the player to move 50 pixels or so on the Y-axis while still travelling along the X with the "left" and "right" keys?
Any pointers?
A couple of things. You may want to take into account 'delta' in your movement script.
In your case you're just adding 2 to the player's position.
That is, if your script runs slower on my machine the player would move slower too.
So what you need to do is multiply the player's speed (2 in your case) by delta and add that to the position.
Since delta is in seconds, you'll probably need to increase the speed constant or your player will move 2 pixels per second.
Second, you don't need parentheses here, because "=" or assignment has lower precedence than addition.
Lastly, yes, sure you can avoid using a "velocity" vector but in that case your character will have NO intertia.
That is, if you release the keys he'll stop moving.
Velocities are not that complicated. Basically, the idea is you keep a velocity vector (vx, vy) and add that vector to the player's position each frame (taking delta into consideration again). When a key is pressed, you change the velocity vector instead of the player's position.
Re: Soooo.....platform jumping?
Posted: Thu Oct 27, 2011 12:31 pm
by GijsB
here's a good example of using velocity to create a fireworks effect :
press space to release fireworks
(i still need to change the numbers a bit to make it more realistic)
Re: Soooo.....platform jumping?
Posted: Thu Oct 27, 2011 1:11 pm
by Benni88
Thanks too guys. I'm working on it now.
Re: Soooo.....platform jumping?
Posted: Thu Oct 27, 2011 1:17 pm
by GijsB
Wait! I changed the numbers a bit, and made everything constant with delta :
Re: Soooo.....platform jumping?
Posted: Thu Oct 27, 2011 3:11 pm
by Kadoba
I've made an example before that shows how to do this. I haven't taken a look at it in a while but it might be useful for you:
http://love2d.org/forums/download/file.php?id=2732
(Use the arrow keys to move)
Never mind, that one isn't speed consistent. Try this one: