- Home /
Question by
Cookiemonster04 · May 23, 2019 at 07:53 PM ·
c#animation2dcircular
Animation disturbing circular rotation
I have multiple child game objects making a circle around a parent game object also facing the parent gameobject. I also added an animation on the parent gameobject & the animation made the child gameobjects rotate on its Z axis instead of moving in a circle.
Vector3 v;
public GameObject go;
public Transform center;
public float degrees = -65;
void Start()
{
v = transform.position - center.position;
}
void Update()
{
v = Quaternion.AngleAxis(degrees * Time.deltaTime, Vector3.forward) * v;
transform.position = center.position + v;
Quaternion rot = Quaternion.LookRotation(go.transform.position - transform.position, transform.TransformDirection(Vector3.up));
transform.rotation = new Quaternion (0, 0, rot.z, rot.w);
}
Comment
Answer by Firox_ · May 23, 2019 at 08:44 PM
transform.rotation just changes the GameObject's rotation. To make an orbit there is transform.TranslateAround: https://docs.unity3d.com/ScriptReference/Transform.RotateAround.html