Hi, I want to learn how to make deceleration for my game. Slope physics would be really really cool, but I wouldn’t need it as much.
For deceleration, I mean having the player slow down when not touching a key and/or moving, such as a player slowing down gradually after letting go of the W key as opposed to immediately stopping. What I mean is close to sonic the hedgehog physics than anything else. Any type of lead would be appreciated.
If your using something like VectorForce or LinearVelocity for your movement, use lerp to smoothly slide the velocity. you could also do this for the walk speed but slowing down wouldnt really do much.
i belive the lerp equation is this:
a + (b - a) * t
a = initial value
b = wished value
c = time; from 0-1 reprrsenting time
Yeah, but it just accelerates the walkspeed exponentially from 0.5 (the original walkspeed) to 200 max. No vectorforces or LinearVelocity. does tha mean I have to chsnge my movement system?
UPDATE: Here are the essential parts of my script
if not (hum.MoveDirection.Magnitude == 0) then
hum.WalkSpeed = speed
speed *= 1.05
if not walkAnim.IsPlaying and hum.WalkSpeed <= 50 and not jumping and not dashing then
if runAnim.IsPlaying or idleAnim.IsPlaying or run2Anim.IsPlaying then
runAnim:Stop()
idleAnim:Stop()
run2Anim:Stop()
skidAnim:Stop()
boostAnim:Stop()
end
trail.Enabled = false
walkAnim:Play()
elseif not runAnim.IsPlaying and hum.WalkSpeed <= 110 and hum.WalkSpeed >= 50 and not jumping and not dashing then
if walkAnim.IsPlaying or idleAnim.IsPlaying or run2Anim.IsPlaying or boostAnim.IsPlaying then
walkAnim:Stop()
idleAnim:Stop()
run2Anim:Stop()
skidAnim:Stop()
boostAnim:Stop()
end
trail.Enabled = false
runAnim:Play()
elseif not run2Anim.IsPlaying and hum.WalkSpeed < 200 and hum.WalkSpeed >= 110 and not jumping and not dashing then
if walkAnim.IsPlaying or idleAnim.IsPlaying or runAnim.IsPlaying or boostAnim.IsPlaying then
walkAnim:Stop()
idleAnim:Stop()
runAnim:Stop()
skidAnim:Stop()
boostAnim:Stop()
end
trail.Enabled = false
run2Anim:Play()
elseif not boostAnim.IsPlaying and hum.WalkSpeed == 200 and not jumping and not dashing then
if walkAnim.IsPlaying or idleAnim.IsPlaying or runAnim.IsPlaying or run2Anim.IsPlaying then
walkAnim:Stop()
idleAnim:Stop()
runAnim:Stop()
run2Anim:Stop()
skidAnim:Stop()
end
trail.Enabled = true
boostAnim:Play()
boostAnim:AdjustSpeed(2)
end
if speed >= 200 then
speed = 200
end
else
if walkAnim.IsPlaying then
walkAnim:Stop()
end
if runAnim.IsPlaying then
runAnim:Stop()
end
if run2Anim.IsPlaying then
run2Anim:Stop()
end
if skidAnim.IsPlaying then
skidAnim:Stop()
end
if boostAnim.IsPlaying then
boostAnim:Stop()
end
if not idleAnim.IsPlaying and not jumping and not dashing and not groundPounding then
idleAnim:Play()
end
hum.WalkSpeed = 0.5
speed = 16
end