Soooo.....platform jumping?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Benni88
Prole
Posts: 10
Joined: Mon Oct 24, 2011 10:34 am

Soooo.....platform jumping?

Post 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?
Attachments
Benni's Project.love
(2.49 KiB) Downloaded 115 times
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Soooo.....platform jumping?

Post 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.
When I write def I mean function.
Benni88
Prole
Posts: 10
Joined: Mon Oct 24, 2011 10:34 am

Re: Soooo.....platform jumping?

Post by Benni88 »

Cheers, I'll have a go at it and come back if i get stuck.
User avatar
ivan
Party member
Posts: 1911
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Soooo.....platform jumping?

Post 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.

Code: Select all

Player_y = (Player_y +2)
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.
Last edited by ivan on Thu Oct 27, 2011 1:16 pm, edited 1 time in total.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Soooo.....platform jumping?

Post by GijsB »

here's a good example of using velocity to create a fireworks effect :
press space to release fireworks :D
(i still need to change the numbers a bit to make it more realistic)
Attachments
fireworks.love
(530 Bytes) Downloaded 94 times
Benni88
Prole
Posts: 10
Joined: Mon Oct 24, 2011 10:34 am

Re: Soooo.....platform jumping?

Post by Benni88 »

Thanks too guys. I'm working on it now.
User avatar
GijsB
Party member
Posts: 380
Joined: Wed Jul 20, 2011 10:19 pm
Location: Netherlands

Re: Soooo.....platform jumping?

Post by GijsB »

Wait! I changed the numbers a bit, and made everything constant with delta :
Attachments
fireworks.love
(535 Bytes) Downloaded 91 times
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Soooo.....platform jumping?

Post 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:
Attachments
JumpExample.love
(2.85 KiB) Downloaded 103 times
Post Reply

Who is online

Users browsing this forum: No registered users and 68 guests