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
Hold To Jump
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- substitute541
- Party member
- Posts: 484
- Joined: Fri Aug 24, 2012 9:04 am
- Location: Southern Leyte, Visayas, Philippines
- Contact:
Re: Hold To Jump
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
Currently designing themes for WordPress.
Sometimes lurks around the forum.
Sometimes lurks around the forum.
- substitute541
- Party member
- Posts: 484
- Joined: Fri Aug 24, 2012 9:04 am
- Location: Southern Leyte, Visayas, Philippines
- Contact:
Doubled post, sorry
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.
Sometimes lurks around the forum.
Re: Hold To Jump
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.
This code sets yvel to zero, if it is negativ, and keeps it unchanged, if it is positive.
Code: Select all
function love.keyreleased(key)
if key == "up" then
player.yvel = math.max(player.yvel,0)
end
end
Check out my blog on gamedev
Re: Hold To Jump
Here's an example on how to do variable jumping.
- WolfNinja2
- Party member
- Posts: 150
- Joined: Wed Oct 24, 2012 10:10 pm
Re: Hold To Jump
But then can't ya just kinda, y'know, fly.....xDmicha 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.
This code sets yvel to zero, if it is negativ, and keeps it unchanged, if it is positive.Code: Select all
function love.keyreleased(key) if key == "up" then player.yvel = math.max(player.yvel,0) end end
- WolfNinja2
- Party member
- Posts: 150
- Joined: Wed Oct 24, 2012 10:10 pm
Re: Hold To Jump
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
He won't even jump -_-
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
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Hold To Jump
You might have changed it by now, but isn't your player.jump function called from the love.keypressed event? 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.
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.
- WolfNinja2
- Party member
- Posts: 150
- Joined: Wed Oct 24, 2012 10:10 pm
Re: Hold To Jump
I didn't know I did that. Did I accedentaly resubmit or kinda make a new thread for the same issue?Puzzlem00n wrote:You might have changed it by now, but isn't your player.jump function called from the love.keypressed event? 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.
And I did change the player.jump(dt) so it was in love.update() so THAT's not it :p
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Hold To Jump
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.
Who is online
Users browsing this forum: No registered users and 21 guests