unity how to make an object rotate around a point code example
Example 1: unity how to rotate something to point to something else
Vector3 dir = target.position - transform.position;
Quaternion lookRotation = Quaternion.LookRotation(dir);
Vector3 rotation = Quaternion.Lerp(partToRotate.rotation, lookRotation, Time.deltaTime * turnSpeed).eulerAngles;
partToRotate.rotation = Quaternion.Euler(0f, rotation.y, 0f);
Example 2: rotatearound unity
using UnityEngine;
public class Example : MonoBehaviour
{
private Vector3 target = new Vector3(5.0f, 0.0f, 0.0f); void Update()
{
transform.RotateAround(target, Vector3.up, 30 * Time.deltaTime);
}
}
Example 3: unity rotate around point
transform.RotateAround(point, axis, degrees);