0 votes

Hi, might be a stupid question but i could not find a way to do it

so i want an object to turn 180 degrees smoothly when a key is just pressed , the code below makes the object turn instantly,

if Input.is_action_just_pressed("turn"):
    rotation_degrees.z += 180

i tried to use lerp but it would not work unless i hold or spam the key, again i'm new to godot and gamedev in general,some help would be amazing.

in Engine by (15 points)

1 Answer

+2 votes
Best answer

Do not change angle directly. Instead add variable desired_angle and interpolate rotation to that angle in _process()

Something like that

func _process(delta: float):
  var diff = desired_angle - rotation_degrees
  rotation_degrees = lerp(rotation_degrees, desired_angle, delta * diff * rate)
by (1,422 points)
selected by

Thank you! it worked.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.