- Home /
Actor animation not matching direction.
Hello, i have a request for help solve/clarify my problem.
I have the player following the cursor/mouse for rotation, while freely controling the charecter with the keybord (horizontal = strafing).
The controller works. My problem is that the animation doesn't match the direction of the movemt. Since pictures sometimes explain better than a thousand words... where it goes!
My charecter controller say forward but my charecter direction/cursor says backwards (since its pointed in that direction) so my animation is in conflict, sort of speak, with my controller since my animation is walking forward. The point is that the animation should be "walking back" since i'm pressing up on the controler.
Now my camera is a 3rd person/top-down semi fixed camera (following player, fixed height, rotating 90degrees around the player when a key is pressed).
Heres my code...
//ANIMATION VARIABLES
float anim_actor_andar;
float anim_actor_andar_lateral;
float valor_correr_para_animacao;
//Velocity
public float Velociade_Movimento_Actor = 1.0f;
public float Velocidade_Rotacao_Actor = 5.0f;
void Update () {
//Mouse rotation and follow
Plane playerPlane = new Plane (Vector3.up, transform.position);
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
float hitdist = 0.0f;
if (playerPlane.Raycast (ray, out hitdist)) {
Vector3 targetPoint = ray.GetPoint (hitdist);
Quaternion targetRotation = Quaternion.LookRotation (targetPoint - transform.position);
transform.rotation = Quaternion.Slerp (transform.rotation, targetRotation, Velocidade_Rotacao_Actor * Time.time);
}
//Movement
float movimento_frente = Input.GetAxis ("Vertical") * Velociade_Movimento_Actor;
float movimento_lateral = Input.GetAxis ("Horizontal") * Velociade_Movimento_Actor;
Vector3 velocidade = new Vector3 (movimento_lateral, 0, movimento_frente);
velocidade = Camera.main.transform.rotation * velocidade;
CharacterController controlador_actor = GetComponent<CharacterController> ();
controlador_actor.SimpleMove (velocidade);
//Animation var's for FixedUpdate
//Tried solution
if (/*Something*/){
//animation act acording
}
else (/*Something*/){
//animation act acording
}
anim_actor_andar_lateral = Input.GetAxis ("Horizontal"); //Strafing animation
}
void FixedUpdate () {
animator.SetFloat ("Velocidade", anim_actor_andar);// Walking
animator.SetFloat ("Direccao", anim_actor_andar_lateral); //Direction / Straffing
}
I tried some solutions like adding a condition with some "targetPoint" values, trying to determin the direction faced by the player and adjusting the value sent to the animator but all have been proven falty..
I don't know if my explanation of my problem is clear or not. I apologize for any gramar errors sinde my language is not english.
I would apretiate any help you can give. Thanks in advance.
Your answer
![](https://koobas.hobune.stream/wayback/20220613152608im_/https://answers.unity.com/themes/thub/images/avi.jpg)