Hi,
I have my eyeball object rotating to follow a target in a really basic 3D scene. I would like to add functionality where if the target is too far away or angle too large, rotate eye back to default. I think I can handle the rotate back to default (moving the rotation out of the transform and into its own values) and if the length is too large (using direction.length()) but I don't know an easy way to get the total angle from the eyeball to the target.
For example, how do I calculate if the target is more than 60 degrees from the default rest position (0,0,0) of the eye?
func _process(delta):
var eye = get_node("MeshInstanceEye")
var target = get_node("Position3DTarget")
var eye_t = eye.get_global_transform()
var target_t = eye.get_global_transform()
# make eye follow target
var direction = eye.transform.origin - target.transform.origin
# TODO: if target too far away or angle too large, rotate eye back to default
eye.transform = eye_t.looking_at(direction, Vector3(0, 1, 0))