Hi, I’m making a simple top down like shooter game and I’m having a problem regarding mecanim and rotation. I’m using the character and animations from mixamo and it was working fine until I add the rotation using raycast and rigidbody. The rotation was working well when I turn off the animator controller or use the capsule as a character.
Here is my movement code.
void FixedUpdate ()
{
float h = Input.GetAxisRaw ("Horizontal");
float v = Input.GetAxisRaw ("Vertical");
Move (h, v);
Turn ();
}
void Move (float h, float v)
{
//movement.Set (h, 0f, v);
//movement = movement.normalized * speed * Time.deltaTime;
anim.SetFloat ("speed", v);
//playerRigidbody.MovePosition (transform.position + movement);
}
void Turn ()
{
Ray camRay = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit floorHit;
if (Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
{
Vector3 playerToMouse = floorHit.point - transform.position;
playerToMouse.y = 0f;
Quaternion newRotation = Quaternion.LookRotation (playerToMouse);
playerRigidbody.MoveRotation (newRotation);
}
}
My player hierarchy is this.
Empty GameObject with rigidbody and scripts->Player Object with the animator Animator
I’m using mecanim rig and animation. The only one that have check in animation is loop time and loop pose and set everything to original. The problem is when I rotate my mouse like in a circle the character moves randomly like it’s following my mouse instead of rotating in it’s place.
NOTE: I try to uncomment the movement for rigidbody and disable the root motion in animator and it’s working like I want. But I want to use the root motion. How can I fix this.