x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Behaviour tree quiqstart guide - new functionality

Hello Guys. I was recently learning about behaviour trees from official quickstart guide https://docs.unrealengine.com/latest/INT/Engine/AI/BehaviorTrees/QuickStart/index.html

Since everything is working perfect, I would like to add a new functionality to this behaviour tree. Lets say we spawn 3 enemies. I would like to add some behaviour to ai enemy - a variable which every one of them would check during the "AggroCheck". To imitate some "swarm" behaviour by using only one variable. I made a sketch of what I would like to achieve, it's on attachment.

alt text

I thought to set it up in "AggroCheck" Service. During spotting player a variable, lets call it "roar" would be setting to "true". In the same AggroCheck, there would be also a node that would be checking if other pawns noticed player. And this is my biggest reflection - how can I make it in this blueprint that the pawn would be checking other pawns around some radius? (to see if they noticed the player).

Product Version: UE 4.18
Tags:
swarm.png (92.5 kB)
more ▼

asked Dec 01 '17 at 06:14 PM in Blueprint Scripting

avatar image

Elcardia
3 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Well you more or less already came to the right Conclusion on your own. So if you see the Player you change your state to Chasing the player and Check if there are other Enemies around you by say Get Overlapping Actors -> foreach -> check if overlapped Actor is already in the Chasing State (to avoid infinite loop, ignore those) if not make him do the exact same thing your first Enemy did (you can create a Function for that). Everyone in Range will end up in the Chasing state. Thats about it in a nutshell.

Good Luck and have Fun =)

more ▼

answered Dec 01 '17 at 07:41 PM

avatar image

Nachtmahr
6.9k 143 26 172

avatar image Elcardia Dec 02 '17 at 08:02 PM

Hello, Thank you for tip, it drives me to the correct way of thinking :D.I think im nearly to win this. Last to things left for me. So in point (1) it's decided wherever enemyCharacter see player or not. If yes, i set "roar" value to true . And a enemyCharacter is receiving both player location and target to follow. If no, I've put a loop foreach actor. Now, i don't know how to set foreach in some radius around. Can you give me another tip? Also in getOverlappingActor, what should i put into blue target socket?

alt text

fix.png (282.6 kB)
avatar image Nachtmahr Dec 02 '17 at 08:20 PM

You over Complicated things there a bit. Look at this example logic as a Guide (Im to lazy to setup a BT now sorry, but the logical part stays the same)

https://i.imgur.com/k7yiPlz.png

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I hope to simplified it with your example, however Im missing where to put As enemy character from "cast to enemy character" node. In the end, it has to go to "set blackboard value as object".

alt text

However now im thinking, isn;t this script is running for every enemy character? So in the end, I may set up this for enemies around but right after this script is running for them and they dont see the character so they stand in place.

fix.png (297.6 kB)
more ▼

answered Dec 02 '17 at 09:57 PM

avatar image

Elcardia
3 1 3

avatar image Nachtmahr Dec 02 '17 at 11:00 PM

But that inside your AI Controller https://i.imgur.com/eYv1L8P.png

In your Service you already got your AI Controller ref so drag a wire out and call that function. I looked at the Quickstart service and you should have your Target to follow from the line trace. But watch out if your Agro Check runs again your Target to Follow will unset (out of sight) so you very likely want to set the Target Location inside your AI Controller too (or only the Location, up to you) so your other Enemies run to the Location the Player was Spotted. Also dont forget that your Agro check executes in periods and you might want to avoid Calling OnTargetSpoted every time. You can avoid this by checking if you got a valid TargetToFollow before calling OnTargetSpoted so it will execute only if Line of sight is established.

I think that should cover all things now xD (I hope)

avatar image Nachtmahr Dec 02 '17 at 11:04 PM

And last addition if you want to keep everything in your agro check you can get the others Enemies Blackboards like that ( I prefer Controller ) https://i.imgur.com/oVG8gmN.png

avatar image Elcardia Dec 05 '17 at 10:41 PM

Now i think i overdid it muuuuuuch.

Round start, enemy are spawning. Im running and get of their sight. They will go to my last known position and after wait time (2.5s) every one of them will go to their home location. Its kinda long cause each of them will go himself after 2.5s after previous one. Then after reaching home location, they will roam from home location to my last known position.

Quite different is when there are already enemies on the level when load. They will go after me, after lost track they will just return to home location. And wont move from there until i will come closer again

Maybe I should really put everything into AgroCheck. But I didnt underseand you picture from AgroCheck.If I noticed enemy, i put it as "YES" node from most right Branch? Im attaching my AggroCheck, EnemyAI, spawne and FollowerBehaviourTree.

[1]: /storage/temp/222694-agrocheck1.png

[2]: /storage/temp/222695-agrocheck2.png

[3]: /storage/temp/222696-spawner.png

[4]: /storage/temp/222697-enemyai.png

[5]: /storage/temp/222698-followerbt.png

agrocheck1.png (349.3 kB)
agrocheck2.png (247.8 kB)
spawner.png (194.8 kB)
enemyai.png (361.8 kB)
followerbt.png (126.8 kB)
avatar image Elcardia Dec 05 '17 at 11:05 PM

Im also receiving an error when spawner is in the game. Problem gone when i delete spawner

[1]: /storage/temp/222700-error.png

error.png (99.1 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question