ive looked at the answers on these forums however there must be an easier way, im moving an object in a circle and am simply trying to rotate the object on the z axis to follow the circular motion. (a car traveling in circle) i tried subtracting the transform.position from the target position, to return a vector, however am unsure how to add that vector simply to the z axis of the object because the difference vector has values for x and y and 0 value for z. i bet the answer is really simple because the (local) rotation should remain the same the entire time its rotating around the circle, right?
public Transform pivotPoint;
public float speed = 1;
public float circumference = 4;
public float count = 0;
Vector3 previousPosition;
void Update()
{
count += Time.deltaTime * speed;
var x = Mathf.Cos(count) * circumference;
var y = Mathf.Sin(count) * circumference;
Vector3 targetPosition = new Vector3(x, y, 0);
transform.position = targetPosition + pivotPoint.position;
}