Character movement with love.physics ?
Posted: Thu May 11, 2017 5:45 pm
Hello everyone!
I'm very new with lua and löve 2D and I'm starting a small game.
I wanted the camera to be directly above the character. So I came up creating a love.physics world with no gravity and I attached the player image to a body I created.
Should I move by character by adding force to the body or by changing the body coordinates ?
I tried to add force to the body with Body:applyForce but the body is sliding along the screen when no key is pressed and the velocity limit I tried put seems kinda glitchy...
I'm very new with lua and löve 2D and I'm starting a small game.
I wanted the camera to be directly above the character. So I came up creating a love.physics world with no gravity and I attached the player image to a body I created.
Should I move by character by adding force to the body or by changing the body coordinates ?
I tried to add force to the body with Body:applyForce but the body is sliding along the screen when no key is pressed and the velocity limit I tried put seems kinda glitchy...
Code: Select all
vx, vy = objects.player.body:getLinearVelocityFromLocalPoint( player_x, player_y )
if love.keyboard.isDown("z") and vy > -100 then
objects.player.body:applyForce(0, -force)
end
if love.keyboard.isDown("q") and vx > -100 then
objects.player.body:applyForce(-force, 0)
end
if love.keyboard.isDown("s") and vy < 100 then
objects.player.body:applyForce(0, force)
end
if love.keyboard.isDown("d") and vx < 100 then
objects.player.body:applyForce(force, 0)
end