This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

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:
https://godotengine.org/qa/26782/vector3-representing-direction-an-object-is-facing

Godot version 3.3.3
in Engine by (23 points)
edited by

1 Answer

+1 vote
Best answer

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.
by (143 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.