Created
September 16, 2019 15:08
-
-
Save RichardEllicott/db35be4e940c496d9dd709470fa17a5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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