Skip to content

Instantly share code, notes, and snippets.

@RichardEllicott
Created September 16, 2019 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardEllicott/db35be4e940c496d9dd709470fa17a5d to your computer and use it in GitHub Desktop.
Save RichardEllicott/db35be4e940c496d9dd709470fa17a5d to your computer and use it in GitHub Desktop.
func my_rotate_towards_lerp(target, delta):
var deg360 = deg2rad(360.0) # is 360 degrees but in radians
var deg180 = deg2rad(180.0)
var node = Node2D.new() #create a new node
node.position = global_position #at the same position
node.look_at(target) #get it to look instead! (missing functions in godot)
#adding 180 degrees is to do with needing to find left and right, like -180 to 180
#adding 360 is just to ensure that once the other rotation is minused, it won't go negative
# (in the end the modulo is to 360 degrees anyway)
var node_rotation = node.rotation + deg180 + deg360
node_rotation -= rotation #this gets the value the node_rotation is relative
node_rotation = fmod(node_rotation, deg360) #this modulo will ensure the value is between 0-360
if node_rotation > deg180: #now if our value is more than 180 it means rotate one way
rotation += delta
else: #or the other
rotation -= delta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment