Unity camera makes circular motion around an object

1.Method 1

target.position is the position of the center of the circle,

Vector3.forward is the axis of rotation (Vector3.up / Vector3.right),

90 means rotating 90 degrees per second, which is 1/4 turn.

The script needs to be mounted on the camera.

public Transform target;

 void Update()
 {
     transform.RotateAround(target.position, Vector3.up, 90 * Time.deltaTime);  
 }

2.Method 2

target.position is the position of the center of the circle,

r is the radius of the circle, which is the vector to be rotated,

transform.LookAt(target.transform), the camera always faces the center object of the circle,

The script needs to be mounted on the camera.

public Transform target;
Vector3 r;

void Awake()
{
     r = transform.position - target.position;
}
void Update()
{
     r = Quaternion.AngleAxis(90* Time.deltaTime, Vector3.up) * r;
     transform.position = target.position + r;
     transform.LookAt(target.transform);
}

3. Operation effect

 

0

Guess you like

Origin blog.csdn.net/qq_2633600317/article/details/131916776