I can't make a character fall down...
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
I can't make a character fall down...
I searched for some Physics tutorials but no luck. All I want to do is if you release the "W" key then the character falls down until it hits the ground. I know you would need some type of ground..and collision detection..and some velocity(I think)..but sadly I don't know much about that. Does anyone know a simpler way?
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: I can't make a character fall down...
Well, this is an odd question, but lucky for you, I'm an odd person.
That should do exactly what you want.
Code: Select all
function love.load()
player = {
x = 380,
y = 180,
grav = 0 -- gravity amount
}
end
function love.keyreleased(key)
if key == "w" then
player.grav = 90 -- we make it a value to go down
print(release)
end
end
function love.update(dt)
player.y = player.y + player.grav * dt -- We add gravity to the player's y position
if player.y > 400 then -- Are we on the ground? (which we'll call 400 y)
player.y = player.y - player.grav * dt -- If we are, We undo that moving down
end
end
function love.draw()
love.graphics.rectangle("fill", player.x, player.y, 40, 40) -- Draw it!
end
I LÖVE, therefore I am.
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 5 guests