Move around while facing the player?

Hey,

I have an enemy which moves around on a Recast Graph using RichAI.
What I’d like it to do is for it to always try to rotate its “face” towards the player while moving as it is now. Since RichAI needs to rotate towards the direction it is moving in this isn’t currently happening. What I need is a strafing enemy, that keeps its rotation on you but moves where the RichAI is moving it.

I though about some parent/child architecture, where one would control the movement and the other rotation but couldn’t really come up with a setup that’d accomplish what I want. Other way could be having the “mover” and the enemy separately, and setting the enemy at mover’s position every frame with correct rotation; however that’d be pretty hacky and i’m not even sure it’d work. I know this may not be exactly A.I. question but I figured maybe someone before had a similar need for a different A.I. movement which would accomplish this (I couldn’t find a thread though).

Any advice is greatly appreciated : )

I more or less got the desired effect by calling this function in the update and putting that script in the child of the gameobject which is being moved by RichAI. It still keeps rotating away a bit sometimes, but overall works.

	void RotateTowardsTarget(Vector3 _target)
    {
     	Quaternion targetRotation = Quaternion.LookRotation (_target - transform.position);
	    transform.rotation = Quaternion.RotateTowards (transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
 		transform.eulerAngles = new Vector3(0, transform.eulerAngles.y, 0);
 	}

I can’t find the actual movement code of A* Pathfinding Project so I’m not sure if this is the optimal way to do this… could you please give insight?

I’ll look into it more, meanwhile I guess if there’s any A.I. movement related solution to this I’d like to hear that also.

Hi

That looks about right. It should be the RotateTowardTarget method that you should modify.

alright, I’ll stick with that then. Now I’m just using simple LookAt with A.I. leading its aim towards player’s movement so it can hit a moving target. That also eliminates the rotating. I can further recode this if need be. If this isn’t suboptimal, i’m content : )