Hold To Jump

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.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Hold To Jump

Post by WolfNinja2 »

Hi, I need an effect where you hold to jump higher, but after so much, you cant jump anymore. Right now my player wont even jump. Here is my jump code:

function player.jump(dt)

local dt = math.min(dt,2)
if love.keyboard.isDown("up") and
onGround == true then
timer = timer + dt
if timer <= 6 then
player.yvel = player.yvel + -100 * dt
onGround = true
end
else timer = 0
end
end

onGround = true anytime it touches the ground so it isn't that.
Thanks!

-Wolf
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Re: Hold To Jump

Post by substitute541 »

WolfNinja2 wrote:Hi, I need an effect where you hold to jump higher, but after so much, you cant jump anymore. Right now my player wont even jump. Here is my jump code:

function player.jump(dt)

local dt = math.min(dt,2)
if love.keyboard.isDown("up") and
onGround == true then
timer = timer + dt
if timer <= 6 then
player.yvel = player.yvel + -100 * dt
onGround = true
end
else timer = 0
end
end

onGround = true anytime it touches the ground so it isn't that.
Thanks!

-Wolf

Just check if the jump button (I will assume it's the spacebar) was held for a certain time, something like 1.5 seconds. Like this :

Code: Select all

-- in love.update
local timer = 0
if spacebarIsDown then
    timer = timer + dt
    if timer > smallTimeInterval then
        jumpHigh
        timer = 0
    elseif timer < smallTimeInterval then
        jumpNormal
        timer = 0
    end
end
Replace the names there with the actual variables/functions.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
substitute541
Party member
Posts: 484
Joined: Fri Aug 24, 2012 9:04 am
Location: Southern Leyte, Visayas, Philippines
Contact:

Doubled post, sorry

Post by substitute541 »

Ooops... I accidentally clicked the post button twice so sorry :(
Last edited by substitute541 on Fri Nov 09, 2012 5:00 am, edited 1 time in total.
Currently designing themes for WordPress.

Sometimes lurks around the forum.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Hold To Jump

Post by micha »

For a really simple implementation of this you can just set the player's y-velocity to zero as soon as the jump button is released.

Code: Select all

function love.keyreleased(key)
   if key == "up" then
      player.yvel = math.max(player.yvel,0)
   end
end
This code sets yvel to zero, if it is negativ, and keeps it unchanged, if it is positive.
User avatar
Kadoba
Party member
Posts: 399
Joined: Mon Jan 10, 2011 8:25 am
Location: Oklahoma

Re: Hold To Jump

Post by Kadoba »

Here's an example on how to do variable jumping.
JumpExample.love
(2.57 KiB) Downloaded 207 times
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Hold To Jump

Post by WolfNinja2 »

micha wrote:For a really simple implementation of this you can just set the player's y-velocity to zero as soon as the jump button is released.

Code: Select all

function love.keyreleased(key)
   if key == "up" then
      player.yvel = math.max(player.yvel,0)
   end
end
This code sets yvel to zero, if it is negativ, and keeps it unchanged, if it is positive.
But then can't ya just kinda, y'know, fly.....xD
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Hold To Jump

Post by WolfNinja2 »

OK I tried a different approach of having the y stored at the start of the jump, then stating that if storedY - player.y = (MaxJump) then
stop the jump... heres my code

Code: Select all

function player.jump(dt)
	if love.keyboard.isDown("up") and
	onGround == true then
	player.yvel = -64 * dt
	jumping = true
	end
	if storedY - player.y == 368 then
	player.yvel = 0
	storedY = 0
	end
end

function player.fall(key)
	if key == "up" then
      player.yvel = math.max(player.yvel,0)
	end
end

function player.store(key)
	if key == "up" then
	storedY = player.y
	end
end
He won't even jump -_-
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Hold To Jump

Post by Puzzlem00n »

You might have changed it by now, but isn't your player.jump function called from the love.keypressed event? :huh: You'll need to change that for any of this code to work. Something to make it called every update.

P.S. I don't really care, but some people on here won't like it when you post twice in a row without good reason. Keep that in mind.
I LÖVE, therefore I am.
User avatar
WolfNinja2
Party member
Posts: 150
Joined: Wed Oct 24, 2012 10:10 pm

Re: Hold To Jump

Post by WolfNinja2 »

Puzzlem00n wrote:You might have changed it by now, but isn't your player.jump function called from the love.keypressed event? :huh: You'll need to change that for any of this code to work. Something to make it called every update.

P.S. I don't really care, but some people on here won't like it when you post twice in a row without good reason. Keep that in mind.
I didn't know I did that. Did I accedentaly resubmit or kinda make a new thread for the same issue?
And I did change the player.jump(dt) so it was in love.update() so THAT's not it :p
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Hold To Jump

Post by Puzzlem00n »

No, it's just bumping it, bringing it to the top of the Support and Development main page when you could just edit your old post. Bumping is generally only accepted for important things, like "new version!" or something like that. (I did it for the collision help thing just because I knew no one would notice the edit otherwise.)
I LÖVE, therefore I am.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 16 guests