I am new to behavior trees and couldnt find a way to do this, what i want is the enemy will move left or right randomly and stop moving that way if there is no where to mov then rotate, go other way and do the same thing again.
Hey @30quickdead!
Check out this tutorial series from Ryan Laley, it covers exactly how to do that and a whole lot more if you’re interested in taking it further!
Disclaimer: This link is not associated with Unreal Engine, Epic Games, or their partners.
But Ryan Laley IS an authorized instructor. The disclaimer is referring to youtube.
Hope this helps!
well not exactly, in the video it makes a patrol path i dont want to determine the way that my enemies go unless there is no other way. Cuz nearly all of my enemies will use this pattern so it will be hard for me to adjust all that points.
Can you describe a bit more about how you are wanting them to move? You could get a random point within a certain distance and then have them move like that?
-
Create a new blackboard key and make it a vector type variable. Open up your AI Controller BP (create one if you don’t have it already), after Begin Play, get a
Random Bool
node, connect it’s return value to theIndex
pin of aSelect
node, right click on the node’s True / False pin, select float on the menu that pops up, then insert 1.0 to one of the pins and -1.0 to the other. Once that’s done, get theGet Blackboard
node, drag out theSet Value as Vector
node, then get aMake Literal Name
node and copy & paste your blackboard key’s name into it, connect it to theKey Name
pin of the node, then right click on theVector Value
pin of the node, hit theSplit Struct Pin
option on the menu that pops up, and plug the return value of our select node into the exposed x component (or might be y, depends on your orientation) -
Create a new task and in the behavior tree, trigger it after a composite of your choice (which to choose depends on your objective, for example if you want the AI character to either patrol or attack, you’d use a selector). Inside the task, constantly trigger an
Add Movement Input
node and assign the world direction to our vector type blackboard key. -
Create a new service and add it to your composite. Inside the service, constantly cast a line trace from the AI character to a little further. You can do that by plugging the controlled pawn’s location into the
Start
pin of aLine Trace by Channel
node, then get theGet Actor Forward Vector
(again, from the controlled pawn), multiply it with your desired value (which would be the margin between the AI character and obstacles), add the character’s location that we got earlier onto it, and plug the result into theEnd
pin of our line trace node. Connect theReturn Value
pin of the line trace node into theCondition
pin of aBranch
node, and after it’sTrue
pin, multiply our blackboard key with -1.
And that should be it! Hope this helps
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.