VaygrEmpire VaygrEmpire - 28 days ago 7
C# Question

how do I make object face player?

I've been following various StackOverflow answers, and I think I found code that works, but before I put any code, I've got to figure out whether or not how Unity knows which way is the "front" of the object.

transform.LookAt(target);


I'm trying to use above code for enemy object to face the player. When I place object into the scene, how do I let Unity know which way is the front of the object? (i.e. I place airplane object into the scene. "I" know which way is the front, but does "Unity" know which way is the front?)

Thank you for your help in advance.

Answer

From https://docs.unity3d.com/ScriptReference/Transform.LookAt.html

Rotates the transform so the forward vector points at /target/'s current position.

From https://docs.unity3d.com/ScriptReference/Vector3-forward.html

Shorthand for writing Vector3(0, 0, 1).

Front is same as forward vector and forward vector is pointing at object Z axis.