I just followed this tutorial: http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/top-down-2d
Where you can take 4 sprites and make an animation just using the 4 frames.
Since my drawing skills are poor, I tried to make a rayman style character, and I made my own animations in the animator:
The game object is compose for a parent body, 2 arm children and 1 head child.
The problem comes when I try to make the character move. This is the srcipt:
using UnityEngine;
using System.Collections;
public class PlayerMovementScript : MonoBehaviour {
public float speed;
void FixedUpdate()
{
Vector3 mousePosition = Camera.main.ScreenToWorldPoint (Input.mousePosition);
Quaternion rot = Quaternion.LookRotation (transform.position-mousePosition,Vector3.forward);
transform.rotation = rot;
transform.eulerAngles = new Vector3 (0, 0, transform.eulerAngles.z);
rigidbody2D.angularVelocity = 0;
float input = Input.GetAxis ("Vertical");
rigidbody2D.AddForce (gameObject.transform.up * speed * input);
}
}
Since I change the rotations to create the animations, the body does not face the direction the mouse is at.
If I use this sprites as animations, the body does face the mouse:
So the question is. There is any way to make a set of sprites animated with mecanim to face the movement direction while still their rotation is modified for the animation?
edit1: The main difference with this example, is that what I try to do, is with a TopDown camera: http://unity3d.com/learn/tutorials/modules/beginner/2d/2d-overview
Edit: Is more info needed?