Changing the rotation of a gameobject that uses AIPath

Hi! First of all great addon for Unity, love it!
I am doing a RTS game and I can move units fine using AIPath.
After finishing movement I would like units to rotate towards enemy’s approaching, the thing is that rotation can’t be done after a target has been assigned to AIPath.
The unit keeps trying to stay on the end point after reaching it, so to prevent this I modified the OnTargetReached() function of AIPath
I put this:

public virtual void OnTargetReached () {
target = null;
canMove = false;

It kind of works but I am thinking this is not the best way. What do you think?

I basically want to cancel or resume a path. Thanks!


Well, that solution works. I would probably have overriden the rotation method and added a check there, but what you are doing works too.

Ok! perfect, thanks! One more thing:
I also want the units AI in this RTS to be able to move to a certain direction while looking and shooting at the nearest enemy.
I tried to override RotateTowards(targetDirection); when there is an enemy nearby, so I can achieve that, but of course it doesn’t works because as the documentation says AIPath will only walk straight while rotating to the direction of the nearest waypoint.
Any solution to that? I was thinking in making the 3D model of the AI as a child of another object and so I can rotate independently the model. What do you think? Thanks :slight_smile:

I just tested it.
Making the 3D model as a child of an Empty Game Object that has the AIPath script works very well for walking in a direction (what AIPath does) while looking at another object at least for now but was wondering if you had another idea.

Thank you for posting about this. I am having the same exact problem.

So I have to turn off canMove, if I want to be able to rotate a gameObject that has AIPath attached to it? Is there no built in way to rotate it?