Hi everyone.
I have a player with two animations, idle and walking, I control a transation with a bool variable, but when a transaction walk to idle, the walk animations is rotating.
At below is coding, video and prints:
void Update()
{
if (Input.GetMouseButtonDown(0))
{
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit))
{
flag = true;
endPoint = hit.point;
endPoint.y = yAxis;
Debug.Log(endPoint);
animator.SetBool ("Move", true);
}
}
if (flag && !Mathf.Approximately(gameObject.transform.position.magnitude, endPoint.magnitude))
{
gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, endPoint, 1 / (duration * (Vector3.Distance(gameObject.transform.position, endPoint))));
//Faz com que o objeto olhe para onde foi clicado
transform.LookAt(endPoint);
}
else if (flag && Mathf.Approximately(gameObject.transform.position.magnitude, endPoint.magnitude))
{
flag = false;
Debug.Log("Change Walk to Idle");
animator.SetBool ("Move", false);
}
}
Thanks!