Hi, probably a very simple answer but i just cant find it.
func _physics_process(delta):
var next_location = global_transform.origin - nav_agent.get_next_path_position()
I’m trying to make my thingy move by smoothly rotating itself to face a given direction. I think the above thing gives me the target position in local space, and I need to rotate it around it’s y axis until it’s z is pointing at the target location’s x,z (not y)
Thanks in advance
Your next_position vector is more like the direction from the target position to the thing’s position. The position is just nav_agent.get_next_path_position().
As @noufany mentioned, there is look_at, but that will snap your thing into the desired rotation, rather than smoothly moving it there. Instead, I’d go with something like:
Find the direction to the target: var desired_direction = nav_agent.get_next_path_position() - global_position (the opposite of what you had in your post - we want the direction from the thing to the target.
Find the angle between whatever direction your thingy is pointing in when it’s Y rotation is set to 0, and your desired_direction.
Use for example lerp_angle to smoothly moved from the current angle to the desired angle