How do I gradually decrease the rotation speed of an object after the key is released?
Thanks!
How do I gradually decrease the rotation speed of an object after the key is released?
Thanks!
We can’t tell for sure if you don’t share your script, but…
If you have a “rotation speed” variable, then you probably set it to 0 when no turn buttons are pushed. Instead of setting it to 0, multiply it by 0.8 or 0.5 every Update().
This is pseudocode, not exact C# or JS code.
thing as Transform
private rotationSpeed = 0.0
def Update():
if Input.GetKey("right"):
rotationSpeed = +1.0
else if Input.GetKey("left"):
rotationSpeed = -1.0
else:
rotationSpeed = rotationSpeed * 0.8
if thing:
thing.transform.Rotate(Vector3.up * rotationSpeed * Time.deltaTime, Space.World)
If you don’t have a “rotation speed” variable, then you probably are just turning the character by a fixed formula whenever the buttons are down. Use a variable instead. The buttons set the variable. The Update decays the variable as above.