Download

Creating a "MatchSpeed" Task in a BehaviourTree for a Motorcycle AI.

Hi there,
I’m attempting to use “Add Movement Input” to allow an AI to cruise alongside the player. My Behaviour first tries to catch up the player, using the BTTask_ApproachPlayer Task in my behaviour tree, as you can see below.

1d8ee6fe03b0c344a568fabefad0db4aedf2200b.png

When BTTask_MatchPlayer is called, I’m hoping for a constant tick, which allows the AI Move To to constantly get the Actor location vector, add 100uu in my direction of travel, and then use this as a destination.

1393cef135eae49dadda83b712153595a5d2e118.png
a06c3ddc7cb38a646164764e5d4f1a30070b8243.png

However, after catching up the player, my AI just stops when it reaches BTTask_MatchPlayer. Have I just made an error with how this is able to be called?
Eventually, I want to grab the speed of the player character and use this to match my AI’s, although right now I’d settle for it moving straight forward using it’s walking speed.

If you want a constant tick, you should use a service not a task. To clarify, I’d have a service which detects if the player is in range. Then two decorators, one if player_in_range is set, the other if not. Then put your tasks under the decorators.

Also, two questions:

  1. why is approach player moving to 0,0,0?
  2. why are you adding +2000 along the x axis? You should be using actor forward vector instead…

Thanks for your response. I’ve made a service and I’m beginning to make the decorators.

In the ApproachPlayer Task it’s taking the player location through “Get Player Character” and putting it in as the Target actor for “AI Move To”. In the MatchPlayer Task the reason I’m adding “GetActorLocation”+2000uu to the x-axis is that my game game has fixed forward movement. I’m using the UE Endless Runner tutorial as a base and I figured that if I just added 2000uu to the AI’s current location it would provide me a destination ahead of the AI for it to pathfind to.

MoveTo will move your bot to the target destination/actor then stop. I believe for matching the speed you don’t even need BT, you can have a formula in your AI controller which takes the distance to the player and calculates the speed. Like: if ai is far behind ai.speed=max speed, if ai is ahead ai.speed=0, if ai is near speed don’t change. One can use a curve for that. If you need to use BTs you will place this in a service, so it runs all the time.

I was able to modify the Match player to fire correctly. In the end I only made one service, which provided a Vector (NextLocation) and a bool (NearPlayer) and put it in my Sequencer. The next difficulty I’m having is the AI MoveTo causing the Rider to stutter everytime I change to a new location. Any way around this? Can I turn down the friction or something, so that the Pawn doesn’t stop completely when I set a new location to move to?