Object's rotation as normalized Vector3

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Oleh Patrushev

Hi. I need to get some object’s normal Vector3.
Object can be rotated, so in normal condition (no rotation) it should be like (0,1,0) or something like that. If it is rotated somehow it should show its direction in world space like face normal.
I know I should try Euler, but no luck I got with it.
I think it should something like object.global_transform.get_world_direction

PS I found something useful here:

:bust_in_silhouette: Reply From: ariel

Try this.

Obtaining the global position of a spatial

var posEnemy : Vector3 = (get_node("SpatialNode") as Spatial ).global_transform.origin 

saves the normalized position pointing towards that place.

	var newPosition : Vector3  = global_transform.looking_at(posEnemy,Vector3.AXIS_Y).origin.normalized()

Because normalization involves dividing by the length of the vector, you cannot normalize a vector of length 0. Attempting to do so will result in an error.

I recommend that you use VScode to have a better autocompletion and reference to the classes.

func Transform.looking_at(target: Vector3, up: Vector3) -> Transform
Returns a copy of the transform rotated such that its -Z axis points towards the target position.

The transform will first be rotated around the given up vector, and then fully aligned to the target by a further rotation around an axis perpendicular to both the target and up vectors.

Operations take place in global space.