Flipping AI character by getting positive or negative value from movement
Hey everybody! I'm having some trouble with flipping an AI character. What I want to do is whenever the AI character moves left or right with this code:
transform.position = Vector3.MoveTowards(transform.position, currentTarget.position, moveSpeed * Time.deltaTime);
The character flips whenever it realizes it's going left and flips again when it's going right. I thought that the easiest way to do this would be to return a value from the movement. Something like when it's moving right the value is 1 and when moving left it's -1. I tried to get the value using something like this:
movex = (Mathf.Abs(GetComponent().velocity.x));
Obviously I wasn't getting anything, because I'm not using Rigidbody2D to move the character, but I don't know how to convert the code to be using transform instead of rigidbody.
Your answer
Follow this Question
Related Questions
How can I flip from 2d to 3d in gameplay? 0 Answers
2D platformer AI 0 Answers
NavMeshSurfaces with Link 0 Answers
my car rolls over to the right always when i run the game and wheels fly away from the car, 2 Answers
Racing game AI question 1 Answer