Home unity3d How to do in unity to make the camera always look at...

How to do in unity to make the camera always look at one object?

Author

Date

Category

Trying to make the camera be tied to one object and watched all the time on another. I need the script to be all the time on one distance from one object and the other was exactly around the middle of the screen. Posted by such a script.

Public Class Cameramove: Monobehaviour {
Public GameObject Player;
Public GameObject Enemy;
Private vector3 offset;
Private Void Start ()
{
  offset = transform.position - enemy.transform.position;
}
Private Void LateUpdate ()
{
  transform.rotation = quaternion.lookrotation (enemy.transform.position - transform.position);
  transform.position = player.transform.position + offset;
}
}

separately everything seems to work, but when it does not work together. How else can I realize my task


Answer 1, Authority 100%

Public Transform Target;
Void Update ()
{
  // Rotate The Camera Every Frame SO IT Keeps Looking At The Target
  transform.lookat (target);
}

Taken from:
https://docs.unity3d.com/scriptreference/transform.lookat.html

Cowwords for which found “Unity Camera Look AT”


Answer 2

Free plugin cinemachine is suitable for camera management. It is difficult to understand, but if you cope the camera and not such miracles will do. For simple actions, it’s like a gun on sparrows, but for something serious I am very advised.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions