I have the RVOController working fine an enemy seeking a target. I would now like the ability to toggle between this normal “seeking” mode and a mode where I am forcing the enemy to retreat in a fixed direction. In other words, cancel the current path and either set the controller moving in a fixed direction without pathing, or be able to create my own path (not relying on A*).
I started digging into the code but I figured I would ask this question before having to pull my hair out…
Thanks!
Hi
Ok, so this depends on what script you are using for controlling the movement.
The RVOController handles the movement, but some other script, like AIPath or RichAI is usually controlling the RVOController.
PS: Maybe you would be interested in the FleePath
My class inherits AIPath at the moment. I haven’t heard of FleePath? Currently AIPath is not allowing my enemy to fall into a pit because it is avoiding the hole. I just want to turn pathing off and force the enemy into the hole.
Ok, I tried FleePath. This class seems to give me functionality that I already have worked out.
My code currently has the AIPath.target pointing to a transform that each enemy sets on every frame. If the enemy is pursuing, the target points to the player, otherwise it points to a location in the opposite direction of the player.
Your target seeker stuff works beautifully! The issue however is that when the enemy is retreating I want your A* not to have to worry about a valid path, I just want to move the enemy straight in the opposite direction. If the pathing is enabled it won’t fall into a pit that the enemy normally has to path around. I am assuming this would happen to FleePath as well?
I tried the FreePath, the problem with it is that once the FleePath has executed my enemy just sits there and I now don’t know how to restart him.
In writing this it just occurred to me that maybe I can just turn off seeking by setting the AIPath.transform to null? will that stop the autopathing?
Thanks!
Hi
To bypass pathfinding for the AIPath, you would need to override it and change how it moves alternatively calculates where to move to.
You could have a bool which toggles following the path or moving straight away from the target.
Yes, that would happen with FleePath as well.
Yup, that is what I did. I overrode CalculateVelocity & OnPathComplete. If retreating do my stuff, otherwise do yours. I needed to handle collisions but now it is working like a champ. Thanks for the help…