Reputation: 875
I'm trying to do a simple thing in unity: rotate an object around an axis. But I'm missing something, my object just goes in the downward direction, instead of rotating around the axis.
This is my update function:
this.transform.RotateAround(new Vector3(1,0,5), new Vector3(0,1,0), 10 * Time.deltaTime);
where (1,0,5) is the center of rotation. My object is at position (0,0,0). The object just moves down, instead of rotating. Any idea why this is happening?
Upvotes: 0
Views: 4761
Reputation: 3964
I think it can solve your problem. This is the script you need:
using UnityEngine;
public class RotateObj : MonoBehaviour
{
private void Update()
{
// rotate to its own axis
transform.Rotate(new Vector3(Random.value, Random.value, Random.value));
// rotate about axis passing through the point in world coordinates
transform.RotateAround(Vector3.zero, Vector3.up, 1.0f);
}
}
and this is your unity configuration:
And it rotates around itself (randomly) and Vector3.zero
coordinates
Upvotes: 1