Platformer Jump Help

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.
ArterianGames
Prole
Posts: 11
Joined: Tue Apr 28, 2015 6:36 pm

Platformer Jump Help

Post by ArterianGames »

Hey ;) Im working on a platformer and I need some help with jumping... How can I make it so I cant fly with it....

Code: Select all

function player.controls(dt)
	if isDown("w") and
	player.yv < 5 then
      	  player.yv = -player.ms
    end
end


function player.physics(dt)
	if player.y < groundLevel then
		player.yv = player.yv + player.grav * dt
	end
end
User avatar
ivan
Party member
Posts: 1915
Joined: Fri Mar 07, 2008 1:39 pm
Contact:

Re: Platformer Jump Help

Post by ivan »

What you have there is the 'jetpack' effect where the velocity is increased over time.
Ideally you want to change the velocity once - when the player presses the jump button...
then you allow gravity to pull the player down.
However if the player releases the jump button while he is still ascending, you set his vertical velocity to 0.
That's the simplest approach and a good starting point.

I wrote a short tutorial about it:
http://2dengine.com/doc_1_3_10/gs_platformers.html
ArterianGames
Prole
Posts: 11
Joined: Tue Apr 28, 2015 6:36 pm

Re: Platformer Jump Help

Post by ArterianGames »

This would be good, if I understood anything... I need a simple gravity and jump thing :D
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Platformer Jump Help

Post by Robin »

The player should only be able to jump when on the ground, something like:

Code: Select all

function player.controls(dt)
	if player.canjump and isDown("w") and
	player.yv < 5 then
      	  player.yv = -player.ms
          player.canjump = false
    end
end


function player.physics(dt)
	if player.y < groundLevel then
		player.yv = player.yv + player.grav * dt
        else
                player.canjump = true
	end
end
Help us help you: attach a .love.
ArterianGames
Prole
Posts: 11
Joined: Tue Apr 28, 2015 6:36 pm

Re: Platformer Jump Help

Post by ArterianGames »

Thank you Robin for the reply ;) It helped a lot! But now if I jump he's just teleports (jumpHeight amount) up, and then down... I would like to make it more smooth... Any suggestions?
Shaddy
Prole
Posts: 5
Joined: Thu Apr 30, 2015 11:26 pm

Re: Platformer Jump Help

Post by Shaddy »

As far as I can tell from the code, you would basically need a way to slowly decrease the players velocity. So when the velocity going up after the jump is set, then you need something that every frame would reduce it by the gravity.
Eg.
love.load()
player.yv = 10
gravity = 2
end
love.update(dt)
player.yv = player.yv - gravity
end

(Im assuming you want something jumping wise similiar to this: https://drive.google.com/file/d/0B8Ox_E ... sp=sharing controls are WASD)
ArterianGames
Prole
Posts: 11
Joined: Tue Apr 28, 2015 6:36 pm

Re: Platformer Jump Help

Post by ArterianGames »

Yeah okay... I did that already, but how to make jump smoother?

Code: Select all

function player.controls(dt)
   if player.canjump and isDown("w") and
   player.yv < 5 then
           player.yv = -player.ms
          player.canjump = false
    end
end
Now it just teleport the player player.ms up...
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Platformer Jump Help

Post by Robin »

Could you upload a .love? It looks like your code conflates player.y and player.yv somehow.
Help us help you: attach a .love.
ArterianGames
Prole
Posts: 11
Joined: Tue Apr 28, 2015 6:36 pm

Re: Platformer Jump Help

Post by ArterianGames »

Emm... I think this is it? :D

Edit: Forgot to put the image in it :S
Attachments
LoveFile.love
I think this is it? :D
(1.06 KiB) Downloaded 64 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Platformer Jump Help

Post by Robin »

Ehm, I can't run the .love or extract the files from it. Are you sure you put your files in a .zip archive, and didn't use some other archive format, like .rar?
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 4 guests