Jumping?
Posted: Mon Dec 30, 2013 7:14 pm
I tried using several methods for jumping, but I can't get any of them to work. Any suggestions?
Code: Select all
velocity = 0
Code: Select all
velocity = velocity + grav * dt
Code: Select all
if jump == true then
if love.keyboard.isDown("up") or love.keyboard.isDown("w") then
player.velocity = -500
jump = false
end
end
Code: Select all
if player.y + player.h < 325 then -- We add player.h because that's his feet.
player.velocity = player.velocity + player.gravity * dt --Add gravity to the velocity
else
player.y = 325 - player.h
jump = true
velocity = 0 --Forgot to add this line in the file.
end
Code: Select all
(Player)
O ____ (ledge)
Y
_______^______________________________ (ground)
Code: Select all
if 350 < x < 456 and --ledge
y + heightsum < 412 then --above ledge
onGround = false --I know I don't need this but wtvr
velocity = velocity + gravity * dt
elseif 350 < x < 456 and --ledge
412 < y + heightsum < 464 then --in between ledge and ground
onGround = false
velocity = velocity + gravity * dt
elseif 350 < x <456 and --ledge
y + heightsum = 412 then --on ledge
Jump = true
elseif x < 350 or x > 456 and --ground
y < 464 then --above ground
onGround = false
velocity = velocity + gravity * dt
elseif x < 350 or x > 456 and --ground
y + heightsum = 464 then --on ground
Jump = true
end
Code: Select all
if 350 < x and x < 456 and --ledge
y + heightsum < 412 then --above ledge
velocity = velocity + gravity * dt
elseif 350 < x and x < 456 and --ledge
412 < y + heightsum and y + heightsum < 464 then --in between ledge and ground
velocity = velocity + gravity * dt
elseif 350 < x and x < 456 --and --ledge --only commented it out to actually get something to work, kind of works
--y + heightsum == 412 then --on ledge
then y = 412 - heightsum
jump = true
elseif x < 350 or x > 456 and --ground
y < 464 then --above ground
velocity = velocity + gravity * dt
elseif x < 350 or x > 456 --and --ground --only commented it out to actually get something to work, right half of map works like the ledge
--y + heightsum == 464 then --on ground
then y = 464 - heightsum
jump = true
end
Code: Select all
====000===== ====000000=====
[P]
x---------------------x
| |
y--------x---------------------x--------------y