Behavior trees functionalities for Player Characters

Hi, I’m working on a game prototype similar to XCOM: EU with party of 4 playable characters. I’ve just recently started working on the AI Behavior Trees and noticed that there’s a ‘Reached Move Goal’ decorator in there. I want to implement similar functionality for my player characters, so that I can turn on the Command UI/Player Input once the player character has reached his movement destination. Unfortunately, I haven’t come across anything similar to that in my player controller. Currently I’m checking every tick if the selected character is moving or not, which doesn’t seem very efficient to me. I would like to know if there is a better way to handle this, like maybe within the player character movement component.

I’ve seen some suggestions on earlier posts saying to use AI controllers for player characters. If I use an AI controller to control my player character movement with BTs, would it be feasible on the long run? I do not want to go ahead with that if I’m gonna lose out on important functionalities in the player controller.

Here’s a video depicting what I’m working on, so that you get a better idea:
UE4 Top Down template Dev Video

Using AI for the actual character and only using the Player Controller to communicate with those AI controllers is pretty common.

Pretty much in every case where a player controls more than one character. XCOM games would count to that but especially strategy games which does this in a lot greater scale with a lot more characters and it still runs great.

So yea. AI with BTs is pretty much what you wanna do :wink:

Cheers

Hey, thanks for the quick reply. So you mean to say that I handle all the input through a player controller that’s not connected to a body. Then communicate with the necessary AI controllers whenever necessary, say like when movement or fire commands are issued. Whereas the basic camera functionalities like rotation and zoom could be called directly from the player controller itself.

Exactly :slight_smile:

Alright, thanks. This should save me quite a bit of unnecessary code. :slight_smile:

Use the AI controller at all times and pass a reference of it to your controller so you can communicate with it.

I’ve been working on implementing an AI controller for the player character. In this scenario, will I have to keep switching between the player controller and the AI controller as the active controller for the player character? Like have the AI controller possess the character during movement and fire commands, then return control over to the default player controller? Or do I need to let the AI Controller possess the pawn by default at level start?

But, if AI controller has possessed the active pawn, and the player controller doesn’t have a body, how do you access this player controller? I mean normally you get the controller for the active pawn and cast it to the particular PC. However in this case, since it doesn’t have control over a body, how can one access it?

You still do the spawn as usual

But via “Event Begin Play” you spawn your AI which then takes control over it and pass a reference to your controller.

EDIT: Nvm sorry. I thought of something else. Just spawn all your character. To use them for certain actions you can use a click event, get the hit result under your cursor and check if it implements your “input pass on” interface (which you will have to create). If it does save it in your controller and somehow mark it as active and do whatever you want from then on (e.g passing down some inputs via the interface to move those characters somewhere else or attack something).

After going through the forums, I’m thinking of having my RTS Cam as the default pawn, rather than a body less controller. As for the actual playable characters, I’m gonna go with the AI Controllers as you said. I’m not sure if making the camera is the best move, but I’m just gonna give it a try since most of what I’m doing in the game is moving the camera around and interacting with the HUD.