Help with my game character's movement
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Help with my game character's movement
I have just started working on my top down game , but I realized that my controls felt too (tight,sharp,)? I set it up so that when I released the button I stopped immediately, this isn't what I want. What I want is for my character to continue in the direction he was going in, kind of like he is on ice, so it doesn't feel so sharp. I am not the best at math so I wasn't able to figure anything out although the answer is probably quite easy , but if anyone could help that would be great! It would also be nice if you explain how your solution worked so I can learn from it. I will have my .love file attached.
Re: Help with my game character's movement
Depends on what library/module you are using.
If you are programming the physics yourself this is one approach to slow down the player velocity:
If you want your player to accelerate gradually, this is another approach:
Once you know the player's velocity this is how you would update his position:
If you are programming the physics yourself this is one approach to slow down the player velocity:
Code: Select all
-- apply linear damping (the greater the "damping" variable the quicker the player slows down)
local d = 1 - dt*damping
if d < 0 then
d = 0
elseif d > 1 then
d = 1
end
-- decrease the player's velocity
vx, vy = vx*d, vy*d
Code: Select all
-- acceleration
xaccel = 0
if move_left then
xaccel = -10
elseif move_right then
xaccel = 10
end
-- accelerate
vx = vx + xaccel*dt
-- limit the velocity (so we don't accelerate to infinity)
if vx > 100 then
vx = 100
elseif vx < -100 then
vx = -100
end
Code: Select all
playerx = playerx + vx*dt
playery = playery + vy*dt
Re: Help with my game character's movement
Thanks for the help I finally got the controls how I want them!
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 8 guests