- Home /
Make a navmesh object start moving in a circle around an object
When my enemy gets within so close to the player it is supposed to start to circle around it. I kind of have this working as I am able to get it to circle around the player without any issue, however what I can not get is for the enemy to start in the correct spot on the circle. As in, when the enemy starts making its circle I want it to start where it is. Instead it moves to a random position on the circle then starts. This is my code so far.
targetDir = mEnemy.transform.position - mEnemy.myTarget.transform.position; targetDir.y = 0; Debug.DrawRay(mEnemy.myTarget.transform.position, targetDir * 5, Color.red, 20f); Debug.DrawRay(mEnemy.myTarget.transform.position, mEnemy.myTarget.transform.forward * 5f, Color.red, 20f); float angle = Vector3.Angle(mEnemy.myTarget.transform.forward, targetDir); Debug.Log(angle); theta = angle * (Mathf.PI / 180); Debug.Log(theta); x = Mathf.Cos(theta) * 5 + mEnemy.myTarget.transform.position.x; y = mEnemy.transform.position.y; z = Mathf.Sin(theta) * 5 + mEnemy.myTarget.transform.position.z ; pos.x = x; pos.y = y; pos.z = z; mEnemy.agent.SetDestination(pos);
I really don't understand why this is not working as my debug tests are showing me that I do indeed have the correct theta. What is wrong with my math?
Your answer
Follow this Question
Related Questions
How to get 0-360 degree from two points 2 Answers
instantiating at different Angles? 1 Answer
Flipping a cube while including the environment 0 Answers
Rotating smoothly between two angles - Mathematical formula? 4 Answers
Get a certain position.. 1 Answer