The player is able to basically glitch it out now because I can jump, hit the other body from below (It is a suspended ledge), then keep hovering mid air.
Otherwise, is there another way to detect if a player is in midair? How can I do this? (But if do it this way, I need something to block off the top of the sprite so that he is "hitting his head" and bouncing off when hitting a body from below)
Here is the code:
Code: Select all
function love.load()
player = {
x = 400,
y = 475,
image = love.graphics.newImage("pig.png"),
body = love.physics.newBody(world, 250, 250, "dynamic"),
shape = love.physics.newRectangleShape(10, 10),
}
player.fixture = love.physics.newFixture(player.body, player.shape) --attach shape to body
end
function love.draw()
love.graphics.draw(player.image,player.body:getX(), player.body:getY(), math.rad(360), 1, 1, width, height+12.5)
end
function love.keypressed(key)
if key == " " then
if jumps>0 then
jumps=jumps-1 -- Allow only double jumps
player.body:applyForce(0, -400)
end
end
end
function beginContact(a, b, coll)
jumps=2 -- Reset jump count
end