How do I change the direction the model is facing on an animation ?,How do I rotate the direction that the avatar is facing on an animation ?
I have three animations and a model I made on Blender and imported to Unity, I checked all the on the inspector and the mesh is not facing the right direction so when the animation is triggered the character is facing to a side instead of forward like so:
I tried the method of creating an empty GameObject with the correct rotation and make the mesh child of it but when attaching the movement script it won't work, I have almost no experience at scripting.
public class Player : MonoBehaviour
{
private CharacterController controller;
private Animator anim;
private Vector3 moveDirection = Vector3.zero;
public float gravity = 20.0f;
public float jumpForce = 10.0f;
public float speed = 50.0f;
public float turnSpeed = 50.0f;
public GameObject runFaceVar;
public GameObject jumpFaceVar;
public GameObject idleFaceVar;
void Start()
{
controller = GetComponent<CharacterController>();
anim = gameObject.GetComponentInChildren<Animator>();
runFaceVar = GameObject.Find("/legoguyIdle2.0/armature/root bone/spine1/spine2/neck/head bone/GEOFaceRun");
jumpFaceVar = GameObject.Find("/legoguyIdle2.0/armature/root bone/spine1/spine2/neck/head bone/GEOFaceJump");
idleFaceVar = GameObject.Find("/legoguyIdle2.0/armature/root bone/spine1/spine2/neck/head bone/GEOFaceidle");
}
// Update is called once per frame
void Update()
{
if (controller.isGrounded && Input.GetKey("up"))
{
anim.SetInteger("AnimPar", 1);
moveDirection = transform.forward * Input.GetAxis("Vertical") * speed;
float turn = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
runFaceVar.SetActive(true);
idleFaceVar.SetActive(false);
jumpFaceVar.SetActive(false);
}
else if (controller.isGrounded)
{
anim.SetInteger("AnimPar", 0);
moveDirection = transform.forward * Input.GetAxis("Vertical") * 0;
float turn = Input.GetAxis("Horizontal");
transform.Rotate(0, turn * turnSpeed * Time.deltaTime, 0);
runFaceVar.SetActive(false);
idleFaceVar.SetActive(true);
jumpFaceVar.SetActive(false);
}
if (Input.GetButton("Jump") && controller.isGrounded)
{
anim.SetInteger("AnimPar", 2);
moveDirection.y = jumpForce;
runFaceVar.SetActive(false);
idleFaceVar.SetActive(false);
jumpFaceVar.SetActive(true);
}
controller.Move(moveDirection * Time.deltaTime);
moveDirection.y -= gravity * Time.deltaTime;
}
}
I copied the code from a tutorial.
Thank you.
fd46g54as.jpg
(30.1 kB)
fd46g54as.jpg
(30.1 kB)
Comment
Your answer
Follow this Question
Related Questions
How to ignore a value while animating 0 Answers
Lerp jumping between two commands 0 Answers
Humanoid Avatar Muscle Pose Issue 1 Answer