- Home /
Want enemy to face the direction he is moving
Good evening,
I have made a game where the enemy bug (blue) is trying to follow the player bug (green). I am using the NavMesh for the enemy bug. I have a video clip of his movement. It does not seem to face the way of the intended motion. Even my son said I have to fix the bug. Haha. Have a look and I would appreciate your thoughts.
Answer by Rickhouse · Jul 31, 2017 at 08:22 PM
You can write a few if statements in the Update() function that gets your position at one frame, then your position at the next frame. If the position increases on the z-axis, then rotate your character to face up and vice-versa with the others!
Or you can try something like: bugAngle = Vector3.Angle (agent.velocity.normalized, this.transform.forward);
and fix it up to rotate up whenever your bugAngle is between 315 and 45 degrees (on a Cartesian plane), and right whenever your bugAngle is between 45 and 135, and vice versa, by writing if statements after!
Could be wrong, but let me know! (Haha hope your son enjoys the new update!)
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Making a bubble level (not a game but work tool) 1 Answer
Need help with char movement. 2 Answers
isGrounded is always false, even with gravity, how do you fix that? 1 Answer
Button Press/Release delay on custom FPS character 0 Answers