Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | fmajor |
I’m very new to godot and making a 2D game in which an object should rotate towards the direction of the mouse movement. I basically want a system similar to many 2D games where the object looks towards the mouse cursor, but instead i want it to follow the mouse movement so that the object can be controlled the same wherever the mouse cursor is. I have managed to achieve a very simple and buggy version of this but i need help to improve the movement to make it more accurate and smooth, or to replace it with a smarter idea. Thank you for your help.
This is my code for it:
func _input(event):
if event is InputEventMouseMotion:
mousedirection = Vector2(event.relative.x, event.relative.y)
func _process(delta):
look_at(position + mousedirection)