Download

Circular Movement using Navmesh

Hi !
In my game i have a enemy and this enemy should walk to me and then move around me. I set up everything in my behaviour tree so he moves toward me but i have no idea how i can achieve the moving around. Can someone help me with this ?

Sort of depends on the game you are working on, I’ve listed two options below. First one would only really work if the levels aren’t super complex or the Enemy is going to be fairly close to the player.

Simple Solution - Not using Nav Mesh
When the enemy gets in range of the player, they enter a new behavior that will cause them to just move in a perpendicular direction to that of the direction to the player. You may then need to add in some slight corrections to the perpendicular direction just to make sure they stay within that set range as they might start to drift outwards. Issue with this is that the Enemy inst really using the nav pathing at this point and may run into some geometry or off of cliffs, but you could add in some basic checks just to see if there are any obstructions in the way. If there are then it can check to see if it can move more into the radius to avoid it and if not then reverse the direction it is traveling around the circle. One benefit of this method is that the enemy will move in a nice smooth circle.

More complex - Using Nav Mesh
Break the circumference of circle that you want the Enemy to walk around into smaller destinations. So when the Enemy gets in range it finds a point 30 degrees from the players location to itself at the distance of the radius. It then just paths to that point and once it arrives gets a new point 30 degrees further along the circle. If a position that it searching for isn’t on the nav mesh then you will need to do further searches for a pathable location less than the radius. This method will take a bit more work to setup but would still have the pawn using the nav mesh. Based on the the number of segments you break the circle up into will effect how smooth it looks traveling around the player.

The one with the navmesh is exactly what i need