- Home /
Adding animation clip stopped my gameobject from rotating.
The gameobjects' rotation is controlled by the Input.acceleration. I created an Idle animation clip for my gameobject, where the object simply oscillates by rotating 3 to -3 degrees in rotate.Z. After I added the animation clip, the rotation is not controlled by the accelerometer anymore and the object faces only in the direction that animation clip was created.
private Animator anim;
void Start(){
anim = GetComponent<Animator> ();
}
void Update(){
float angle = Mathf.Atan2(rigidbody2D.velocity.y, rigidbody2D.velocity.x) * Mathf.Rad2Deg;
if (speed.magnitude > 0.5f)
transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
}
Answer by MikeNewall · May 24, 2014 at 09:48 PM
The animation will override the rotation from the accelerometer. Create an empyy game object and parent your animated object to it. You then want to rotate the parent object using the accelerometer.
I never knew animation overrides the Input values. Wow, that is something new that I learnt today. Thanks for the help, @$$anonymous$$ikeNewall .