Hello,
I am currently programming Ai and now I would like to know how to program it so that if the AI overlaps with this collision box I have, which is a fenced area, once inside the fence area, the Ai will stay in that area and not leave?
If someone can give me some ideas (with images) that would be great!
thanks!
it all depends on how you are implementing things. are you using behavior trees or script? how are you telling the ai where to go? is it a pawn or a character?
the most basic idea is that you only give the ai a location in the box area to move to. so on overlap set a flag(variable) that tells the ai your in the box and have a script that checks for that flag when setting the move to location. you could easily implement a switch or select node to accomplish this.
set a bool in blackboard bisinfence .then once its in fence make it true and on your behavior tree set a behavior that bool was true then get random point from navmesh (random point origin should be center of the fence and radius should be touching walls of the fence) then move to that point wait a second or more and then find another point in that fence
heres a example of how you could setup the system overall. so we begin with a event called move which moves to the pawn to a location. the location used is determined first by if the pawn is in the fenced area via the get “isFenced?” variable and the select node. the select node returns a value based on if the input is true or false in this case.
now as for getting the specific location i included a few methods here. first for the normal roaming movement we use a get random point in radius based on the pawns location. this will give us a random pint in a circle around the pawn. as for movement in the fenced area i used a random point in bounding box coupled with project to navigation. this works as it sounds, you provide a box and it returns a location within the box and tried to find a point that has navigation. you should note here that you will need a reference to the fence actor to get the box dimensions. to get teh reference i used an overlap event in the example. as you can see on begin overlap with fence actor we save a reference to the actor in a variable and set that we are now in the fence.
I tried using behavior trees before but my AI couldn’t recognize the code. I used it to program roaming and it didn’t roam. It seems that blueprints work better.
Also, my fence is not an actor, so is there a way to do this code with like objects? Because the fence I am using, does not change into an actor when I select it in the blueprints.
everything in the level is a actor in a sense. but anyways how are you creating the fenced area? if its something you are planning to use more than once in the game then its probably worth making a bp actor for the fence. if its a one off deal then you could get away with just setting up the components in the level (mesh & collision volume) and doing a script in the level bp.