Auto Targeting

Hello Unity3D i have a question about auto lock on target?Is there any tutorials on how to make my character auto lock on another character?for example im making a 3D fighting game and i want the characters to auto lock on the other characters so that when im fighting i dont have to manually lock on the opponent,its automatically targeted on that opponent?Does anyone know any tutorials on auto targeting or know codes for it on a website perhaps?

It’s simple and doesn’t require a tutorial thanks to Unity

Just use this line in your code:

transform.LookAt(otherCharactersTransform, Space.World);

Docs: https://docs.unity3d.com/Documentation/ScriptReference/Transform.LookAt.html

Or you can work out the rotation and then apply it by using:

Quaternion desiredRot = Quaternion.LookRotation(otherCharactersPosition, Vector3.up);
transform.rotation = Quaternion.Lerp(transform.rotation, desiredRot, speed * Time.deltaTime);

Docs: https://docs.unity3d.com/Documentation/ScriptReference/Quaternion.LookRotation.html

LookAt is easier to use but LookRotation will create a smooth effect as it uses Lerp which LookAt does not.

Feel free to ask for more detail

Minchuilla