Detecting collisions

Hi all,

I implementing a Behaviour Tree Task called Move Away that will enable the NPC to move away when detect light cone collision overlap.

In the image below I am not sure if I should be linking the white lines for cast to TPS as I only requires the cone collider component from TPS and from there when I try to access the cone’s overlap node, it customized out a new one with bind event to overlap so I tried linking/unlinking to test if it prints anything when collided but unfortunately not.

The light cone in TPS blueprint could not detect any collision via component hit or overlap begin.

Would like some advice on how can I detect collision properly when the light’s cone overlap on the NPC.

First off, i’m not an expert. Take my words with a grain of salt

Second off… TPS is the hero character as in the player character right? If it is then the cast is always failing cuz youre casting the player character to the ai character (or vice versa). Not good. If its the player character add a get player character node and hook ut up to the object.

If TPS is the ai character then you should drag out a get ai controller node from controlled pawn and drag out get controlled pawn. I used to have a problem with casting to ai in tasks as well and i dont know why it works this way and not just from the controlled pawn node on the recieve execute. I honestly don’t.

Third off. If i understand you correctly, you want the move away task to execute when the ai character collides with the cone right? If so, you should just set up a component begin overlap in the ai character blueprint, check if other actor is TPP then check if other component is the cone. Then for each loop of all ai controllers with a branch to check if it is same with a get ai controller node for self reference. Then you add a blackboard value (figure out what value works with you, bool probably) and back at the ai char BP after the branch is true you set the value to true if its bool or whatever. And have the task under a decorator with that value. Dont forget to make the other decorators abort on change.

It’s janky, It’s complicated, and probably not the best solution, but it has worked with me when coding in the different hostility states for my own ai without a noticable performance drain.

Hope i was able to help you out, make sure to update me on wether this helped or not :slight_smile:

Hi @zamielGrimwalker sorry this is the updated correct version of the task blueprint

This doesnt really help me out too much. If you can answer these two questions i may be able to help you better:

  1. What is the thirdperson character? The player character blueprint? The ai character blueprint? Or is it something else?
  2. you want the ai character to execute the move away task when it collides with the cone that is coming from the player or another actor? Am i right or am i wrong?

Well off the top of my head the first problem is that you’re only doing an execute, you’re not actually receiving any ticks so it won’t pick up on those things except if it is in the light the very instant it starts executing. What you want is a service to check for light instead which begins with EventReceiveTick.

And what I’d do with event ticks is something like:

Provided the cone of light is an actor. You of course connect the true pin of the branch to the rest of the code you wish to execute if it is not in the light. The == condition on the branch in the top event would be equal to the light cone actor. You can also detect where it is and move in the opposite direction, the randoms are just to illustrate.

Huh. I actually didnt think you can put normal events inside tasks. Well you learn something new everyday.

However, i’ve tried to do somwthing similiar with determining what behaviour the ai should take according to its awareness by checking the awareness float in a service, and it caused the ai to have a hivemind mentality even though the awareness BB key isnt instance synced because (at least i think) all the behaviour trees check the awareness of the same controller.

So if OP wants the ai to respond individually to the cone and not have to go through the pain i had to go through, he has to set the overlap event inside the character blueprint and changes the blackboard value of that instance’s controller and only the controller of that instance from the character blueprint.

There are other ways to go around this problem. Thats the charm of coding there is no set in stone solution to anything. This is the path i chose to take and it worked out just fine. Youre free to go around your own way. Ive only given my two cents on the problem.

  1. Yes the Third person character is the player.
    This current task bp you are looking at is the NPC’s

  2. Collides wit the player’s projected cone and moves away from the player.

I just need the simplest way to get it work first as this is suppose to be a prototype demo.

Yes, have added a light cone actor will try to do this. Problem is the light cone is a child actor created not by me but my teammate. It has no overlapping for me to use on inspector.

hi @crowley caine! the AI is suppose to move away in any random direction given as this is to simulate fear of the light source. Anyone would run in any direction from a danger.

Am I suppose to do the one you explained in the task blueprint or TPS blueprint?

In the task blueprint from behavior tree, there is no Event ActorBeingOverlap and Event tick (replace with Event receive tick)

Well you can make it as a service in a behavior tree or you can just toss it into the character blueprint. If it was in the behavior tree you’d use a service to check if the character is touching the light and have it set a blackboard key based on that (a bool variable), then use that to tell it to move away before it goes back to its normal tasks.

It’s a bit more involved with the structure setting it up in behavior tree but the basic functionality would be as I showed in the picture higher up.

If what I’m saying now is unclear please ask and I will attempt to clarify. This is an example the behavior tree from the quickstart guide:

What you want is essentially the same thing. That tree checks if the AI has a target, then follows that target. If it doesn’t have a target, it returns to its “home location” (Ie it’s starting point). In your behavior tree you’d have a similar service, except checking if the character is overlapping the light actor. If it is, it performs task “move away”, if it isn’t, it goes about its usual business.

I personally prefer to use blueprints for scripting AI as it makes the setup less cumbersome to me, but to each its own. Behavior trees have performance advantages of course.

https://docs.unrealengine.com/en-us/Engine/AI/BehaviorTrees/QuickStart

The cone is a component of the player character blueprint, i presume?
If so, try this out inside the ai character blueprint: http://imgur.com/gallery/MAr2fz9

I cant access my pc right now so youll have to do with this mocked up version. Sorry.

I left out the blackboard value parameters for you to decide since its gonna depend on how your behaviour tree is set up.

If you want all the instaces of ai to move away, the blackboard value you will set has to be instance synced, if not then dont check that box

Also dont forget to set up the other decorators in your tree to abort on value change and you might also need to set the blackboard value in order TO change that value for the decorators to abort.

In my case for example, i have an enumeration set up with all the different states of the ai (patroling, suspicious, searching, hostile, etc…) do i would add a new value to the enumeration and call it moving away and set its value in the blackboard node in the image. Its up to you to decide.
Hope this helps you out. I know your pain since i struggled when i was making my ai.

Last night I made my TPS blueprint to be able to detect the NPC character in the scene with linetrace.
Example: torch light on → starts to linetrace non-stop to check if hit NPC, if hit set boolean to true.

Do I pass the boolean value from TPS bp to the behavior tree’s task blueprint
or behavior tree’s task blueprint should have a boolean variable, from TPS i somehow set the boolean variable that i have access it from the task blueprint?