Hi, in the game I’m developing, when the player is afk, he’s possessed by an AIController and I’d like him to walk around the level, I’ve tested the “GetRandomPointInReachableRadius”, it works more or less but it’s not very natural because he’s constantly turning around, So I tried the spline technique, but it didn’t really work. I was wondering if there was a way of maybe combining the two techniques or antoher way so that when my character is possessed by an AIController, it wanders randomly around the level like a player, following a path that I can define.
One way to avoid the issue of randomly walking two meters and turning around would be to use the environmental query system, and generate path points in a cone. This would make them walk mostly fowrward-ish. Then if you store the initial afk location as a variable, you could loop the cone-based pathing a few times and send them back to start so they don’t wander too far.
While not super realistic if you watch it loop a few times, it would be more flexible than having to manually setup spline paths everywhere.
Adding things the player (and npcs, if applicable) can “do” may also help. Be it furniture they could sit on, or just a virtual point-of-interest where some idle animation plays. Depending on the theme/setting of the game, this could be a book shelf where the idle event adds a book prop to the char’s hand for them to read. Or if it’s a modern setting, have an animation where they check their phone.
If there’s nothing obvious nearby one might use (or you don’t want to fiddle with props), it could be as simple as a place with a nice view where the char plays an anim like they’re looking off in the distance, or a suspicious looking rock to “investigate.”
Thanks for your reply, i think it might work but how can i generate path point in cone ?
Maybe with this node : Random Unit Vector in Cone in Degrees ?
The cone thing isn’t a regular BP node, it’s a environmental query generator. If you’ve never played around with EQS, Epic has a helpful video talking about it here:
A lot of the vid is about behavior trees, but environmental queries can also be run from blueprints.
Thank you very much, I followed the tutorial and learned a lot about how behaviors tree and environment query system work. I have a problem though, when my player character is afk and gets possessed by the AIController, it starts the behavior tree, when I re possess it and it’s no longer afk, it stops the behavior tree, but when I’m afk again and the player character gets possessed by the AIController again, the behavior tree gets stuck on one of the tasks.
My Behavior Tree
The EQS
My Player Controller where i possess/unpossess depending on if the player is afk or not
Hmm… not sure why that would happen. Could be that the engine hasn’t destroyed the first ai controller yet, and subsequent re-possessions are trying to run on an orphan?
Calling the function to possess player with every input might be confusing it somehow too.
Instead of directly calling to possess and delay all the time, maybe use the Any Key event with a branch to only call possessplayer if afk, and both branches converging to set a timer which calls your posessai when it finishes.
if you aren’t using procedural or massive levels, probably the simplest thing to do is just manually place a few points of interest and have the AI go to them in order. You can have them in an array.
Make another version of the array - each time you reach one of hte points, remove it from the array. Once it is empty, reset the array from the original, shuffle it, and keep going.
The benefit of simple system like this is that you can code it in 20 minutes, it will be easy to debug, and then your big thinking energy can go towards higher priority things.
It sounds like a good idea, but I’m having a hard time implementing what you’re telling me.
well feel free to ask questions about specific parts if you need to.
it helps me to try to write out the code in outline format first. Big steps, then break them down into smaller steps. Then it will be easy to identify which parts you don’t know how to do yet