How to get rotation Z (0 to -/+180) values using look_at?

Godot Version

4.2

Question

I have an arrow pointing to -z direction with camera top down view. By using look_at() I could get angle between arrow and player like this

@onready var player = $Player
@onready var node3D = $Area3D/Node3D

func _process(delta):
	node3D.look_at(player.global_transform.origin,Vector3.UP)
	print(node3D.rotation_degrees.y)


It returns arrow’s rotation Y values between 0 to +/-180 when the player walks around it.

But when I tried doing this side way this codes no longer produce 0 to +/-180 values. eg.

func _process(delta):
	node3D.look_at(player.global_transform.origin,Vector3.LEFT)
	print(node3D.rotation_degrees.Z)

How can I get those values when I have my arrow side way and camera with front view? I tried playing with arrow rotations/direction and Look_at Vectors but could not reproduce those same values.
Thank you.

With euler rotations you need to change order of the axes to get different ranges in the rotation property.

1 Like

var angle = Vector3.RIGHT.signed_angle_to(node3D.global_basis.z, Vector3.BACK)

got answer from another forum.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.