News › Forums › RAIN › General Discussion and Troubleshooting › Using Detect
This topic contains 36 replies, has 7 voices, and was last updated by prime 2 years, 2 months ago.
November 29, 2022 at 2:47 pm #5691
Hi, I brought this over fromm post at…
It was probably the wrong place, and NOW I have a more specific question. (Probably better to break down my huge rambling monologue into short concise issues… failing so far, sorry..)
So I need to have a wandering NPC detect my Player Char, and IMMEDIATELY quit its wandering and go/run home, cos Im a badMF.
Im not understanding how to set up a detect node. I would have expected it to work better as a branching node, so that if NON detection happened we go one way, but if detection happened it would go another way.
But RAIN seems to want to do everything by whether a collection if things is true or not.
So I put my detect node under a parallel that also contains the “things I want him to do” if the detection happens. (is this right?)
The OTHER option (what happens BEFORE detection) is all under a random node, just because its a few random things that the NPC does untill he detects me.
But the actual CHOICE node should be what? Ive tried Sequencer, and Selector.. I think Sequencer is wrong (as shown in the image) as it will go thru the first choice before checking the detect right? But I cant get Selector to work either.
I need the detect to work IMMEDIATLY the NPC spots me, whatever he is doing at the time, then switch to a series of actions, that will not loop out of. (I actually need him to enter a house, and stop. Waiting for me to be out of range again, before tentatively emerging into the street again.
I think that the detect IS working, because some or other random settings (that didnt work) the npc DID spot me and walk, but not correctly.
Heres what I am trying, please tell me what IM doing wrong!
November 29, 2022 at 7:12 pm #5695
This was my response to your other post:
Easy enough. Put a parallel as your top node. Add a Detect node that repeats forever and looks for the aspect you placed on the player. Use the Form Variable to hold the result (let’s call the variable player). Next add a Selector. In that Selector add two Constraints. The first Constraint will evaluate “player == null”. Place your normal path behavior in that one. The second Constraint will evaluate “player != null”. Place your run home behavior in that one. Run home can be as simple as a Move with a Vector target.
So, if I’m reading your BT correctly, your random node would go within the first constraint. Move the detect out of your bottom parallel and use it per my suggestion. Then your second constraint would contain a parallel with a move and an animate.
Also, you should probably set your move nodes to repeat forever in your patrol branches. I’m assuming the timer returns true to kick you out of that branch.November 30, 2022 at 8:57 pm #5701
Thanks for the reply Prime.
Still not working Im afraid, but I certainly GET what you meant here.
IM not too sure how to set all the repeats on all the nodes (apart from the ones you told me). But more worrying, Im not sure that the detect is working at all. When I enter the area depicted by the Visual Sensors gizmo, nothing happens at all.
So firstly, is THIS what you meant?
The detect is set up thus:
The first constraint is:
The second is the same only with playerVar != Null (Should I have “” around this, thus”playerVar != Null”???)
And finally, the Entity on my Player CHaracter is set up thus:
Anything here wrong?
Sorry if I seem completely stupid, I tell ya, I feel it right now… But am REALLY looking forward to gettin my head around this, its going to be awesome I can feel it!!
MarkDecember 2, 2022 at 9:58 am #5709
Im 90% sure that the problem is in the setting up of the sensor and the entity.
I have changed one thing above. The form variable on the detect node is changed to SimplePlayer just because THAT is the name in the Entity on my Player character. I dont know if this is correct (I just tried it cos they were both called Form). It has an Visual Aspect called Me.
The constraints also have new Var names SimplePlayer == Null. etc.. Again.. just.. er.. because.. trying a few things.December 2, 2022 at 12:44 pm #5711
ONE STEPP CLOSER STILL:
I had not noticed the hint on the Detect Node. …Store the result in an AI Memory Variable.
So I go to the memory tab of my AI and add a variable name. (What type? I tried a few, string, bool etc)
This variable name is the same thing I put in the constraints AND that is in the detect node Form Variable slot(Not sure WHY Form , but its what you said.. can you elucidate?).
Still not working, but getting closer every minute I think…?
December 2, 2022 at 2:30 pm #5715
- This reply was modified 2 years, 4 months ago by markfrancombe.
- This reply was modified 2 years, 4 months ago by markfrancombe.
I believe @prime said to use a Form Variable as it looks like you did in the screen shots.
To the best of my knowledge, if you use a Form Variable it is stored as a GameObject in the WorkingMemory. While your NPC is running in the Unity Editor, click on the AI child gameobject so you can see the AIrig and the RAIN components. Click on the Memory icon (the leftmost) and look at the values that are in the memory.
NOTE: You may need to click off the Memory icon and click on a different one and then back again to “refresh” the contents of the memory. @prime mentioned in a reply to me that there are some issues with refreshing the contents of the AIrig in the Unity Editor and that’s the best way I have found to force it to refresh.
From my recollection, the variable shows a little icon next to the detected object which I believe represents the gameobject (a.k.a. form) that the Aspect is attached to.
Hope that helps. Good luck.December 2, 2022 at 2:40 pm #5716
That helped ALOT!
It helped by showing me that I DIDNT have to SET a variable in the memory tab, its done automatically!
So I can see BOTH my moveTarget variable and my detect variable being created. However the detect variable, is staying at NULL. So my detect is not working, as I suspected. I can see that the Behavior tree IS reading the detect node (its going orange) but nothing is changing when my Player intersects the AIs Sight Sensors area.
I wonder why?December 2, 2022 at 4:23 pm #5724
Where is the FPSCamera you are using for a mount point? And do you have RequireLineOfSight checked in your Sensor? (Thanks for all the various screenshots. It helps.)December 2, 2022 at 11:02 pm #5747
FPSCamera was just a point on my character rig, kinda head height… And yes I do have require line of sight checked. This is because its for a part of my game where you must creep up on some AI talking and overhear their conversation, if they see you they run off.
MarkDecember 3, 2022 at 1:05 am #5748
Make sure that, if the mount point is inside the colliders on the player, you set up the line of sight mask so that it ignores those colliders.December 3, 2022 at 1:55 pm #5754
That might be the thing… testing now, its looking good!
MarkDecember 4, 2022 at 3:18 pm #5769
Result, not without speedbumps. Now I have got the detct working, yes it WAS the collidor getting in the way. I parented a empty GO to my Player now.
But now.. when I enter the area defined by the AIs sensor, it STILL doesn’t switch over to the other constraint.
OR.. wait… it does now.. and he is moving towards his home (see original requirements)but not playing animation, and another thing.. he only does it AS LONG AS I am within his Sensor area. I want the detect (I think) to cause a switch in behaviour, so he runs home whatever… Then once he has disappeared inside a house (another upcoming requirement, have the AI disappear… Hmmm) he should wait a bit THEN if IM not within his Sensor area, come out and start his wandering.
So current issue is:
How can I get the Sensor trigger to be persistent, and play a behavior to end, rather than only happening when Im close enough?
MarkDecember 4, 2022 at 4:57 pm #5770
Try putting your detect in a sequencer and set a flag. Like:
— Detect (player)
— Expression (foundplayer = true)
Then switch your behavior not on player != null but on foundplayer == trueDecember 5, 2022 at 6:36 am #5780
Are you saying to completely rearrange my tree now? Are we replacing my CONs with a SEQ now, so the detect moves the behavior from the first path (the wandering RAN loops) to a second path (that is currently in my second CON?
OH dammit… heres another Screeny…!
I do GET what you are suggesting, but Im overwhelmed by the amount of options it soon adds up to with every node having repeat settings and fail/succeed settings… Thanks you so much for hand-holding me through this… Im sure Ill get it in the end! (???)
MarkDecember 5, 2022 at 1:45 pm #5781
Ok, now that I see your tree, unless there are some other issues, just take that lonely detect node at the bottom and wrap it in a Sequencer like @prime suggests. Then, in your two CONSTRAINT nodes, just replace your original variable with the result of the foundplayer.
So, in the “Run home in fear” branch, your constraint would be “foundplayer == true”. Then only when that is true will he execute this.
Not sure about the proper way to set the repeat until. In my own tree, the whole thing keeps restarting so that I was seeing some strange behavior (or at least, unexpected based on my limited understanding).
You must be logged in to reply to this topic.