News › Forums › RAIN › General Discussion and Troubleshooting › Idle/roam until player is detected
This topic contains 11 replies, has 3 voices, and was last updated by CodersExpo 1 year, 10 months ago.
-
AuthorPosts
-
March 4, 2022 at 8:40 pm #9034
Hello,
I was trying to create a behavior tree where the NPC is in an idle state (just standing or walking around) until he detects the player (i.e. with an AudioSensor). But I don’t get it. How do I interrupt the idle? Here’s my approach so far:
The problem is that as long as no player is detected this tree will determine a new random target each frame. Any ideas on how to fix that?
Greetings
BrightBit-
This topic was modified 1 year, 11 months ago by
BrightBit.
March 4, 2022 at 10:37 pm #9055put a constraint around the idle that checks to make sure the player is not detected. that will force it to stop running idle and move on. For the detect, I would get rid of the sequencer and the expressions. Just do ListenForFootsteps and have it repeat forever. Since it happens in both of the two Selector choices, you might create a root parallel and put the detect up there, always running.
Parallel
— Detect Footsteps (repeat forever)
— Selector
—-Constraint (player detected)
—— Chase and Attack
—-Constraint (player not detected)
—— IdleStateMarch 5, 2022 at 7:41 am #9079Hi prime,
thank you for your answer but it also didn’t work. However I made it working with a different approach. By comparing my solution with your suggestion I still have to say that I don’t understand why my solution is working and yours is not:
March 5, 2022 at 11:23 am #9086I made a small video to illustrate my problem even better: Illustration on YouTube
Small Note: The debugging of the tree doesn’t seem to be right: I’ve started the game in unity while the pause button was also activated but the tree was nevertheless already completely coloured. BTW: Red nodes returned “failure”, Green nodes returned “success”, Yellow nodes returned “running” and blue nodes had not yet been reached, right? That leads to more questions:
1. Why is the “WanderAround” node blue (see end of video)? There are obviously some pathes, so it can’t be blue.
2. What are orange nodes for?March 5, 2022 at 5:46 pm #9112What are the success/failure conditions on your parallel (named “parallel”)?
March 5, 2022 at 6:04 pm #9115The conditions for the parallel in my solution are:
Fail: any
Succeed: allMarch 5, 2022 at 7:22 pm #9136In case you have additional questions, here’s the complete tree:
<behaviortree version="1.1" repeatuntil="" name="ZombieBehavior2"> <selector usepriorities="False" repeatuntil="" name="root"> <selector usepriorities="False" repeatuntil="" priority="" name="Chase and Attack"> <sequencer usepriorities="False" repeatuntil="" priority="" name="Move"> <expression returnvalue="evaluate" repeatuntil="" priority="" name="HumanoidFound" expression="foundPlayer == true" /> <mecparam valueexpression="1" repeatuntil="" priority="" parametertype="boolean" parametername="Walk" name="EnableMecanimWalkState" damptime="0" /> <move turnspeed="" repeatuntil="" priority="" name="move" movetarget="player" movespeed="" facetarget="" closeenoughdistance="0.0078125" closeenoughangle="" /> <mecparam valueexpression="0" repeatuntil="" priority="" parametertype="boolean" parametername="Walk" name="DisableMecanimWalkState" damptime="0" /> <expression returnvalue="success" repeatuntil="" priority="" name="Lost Player" expression="foundPlayer = false" /> </sequencer> <sequencer usepriorities="False" repeatuntil="" priority="" name="DetectHumanoid"> <detect sensor=""SuspiciousSoundsSensor"" repeatuntil="" priority="" name="Listen for Footsteps" entityobjectvariable="" aspectvariable="" aspectobjectvariable="player" aspect=""Footsteps"" /> <expression returnvalue="success" repeatuntil="" priority="" name="Found Player" expression="foundPlayer = 1" /> </sequencer> </selector> <sequencer usepriorities="False" repeatuntil="" priority="" name="IdleState"> <parallel tiebreaker="fail" succeed="all" repeatuntil="" priority="" name="parallel" fail="any"> <sequencer usepriorities="False" repeatuntil="" name="DetectHumanoid"> <detect sensor=""SuspiciousSoundsSensor"" repeatuntil="success" priority="" name="Listen for Footsteps" entityobjectvariable="" aspectvariable="" aspectobjectvariable="player" aspect=""Footsteps"" /> <expression returnvalue="success" repeatuntil="" priority="" name="Found Player" expression="foundPlayer = 1" /> </sequencer> <constraint repeatuntil="failure" name="selector" constraint="foundPlayer == false" /> <random repeatuntil="running" name="ChooseIdleBehavior"> <sequencer weight="" usepriorities="False" repeatuntil="" name="WanderAround"> <action repeatuntil="" priority="" parametervalues="" parameters="" namespace="(global)" name="Choose Target" classname="AIChooseWanderTarget" /> <sequencer usepriorities="False" repeatuntil="" priority="" name="Move"> <mecparam valueexpression="1" repeatuntil="" priority="" parametertype="boolean" parametername="Walk" name="EnableMecanimWalkState" damptime="0" /> <move turnspeed="" repeatuntil="" priority="" name="move" movetarget="target" movespeed="" facetarget="" closeenoughdistance="0.0078125" closeenoughangle="" /> <mecparam valueexpression="0" repeatuntil="" priority="" parametertype="boolean" parametername="Walk" name="DisableMecanimWalkState" damptime="0" /> </sequencer> </sequencer> <sequencer weight="" usepriorities="False" repeatuntil="" name="HoldPosition"> <mecparam valueexpression="0" repeatuntil="" priority="" parametertype="boolean" parametername="Walk" name="EnableMecanimIdleState" damptime="0" /> <timer waitforsec="2" returnvalue="success" priority="" name="timer" /> </sequencer> </random> </parallel> </sequencer> </selector> </behaviortree>
March 7, 2022 at 12:08 pm #9361I’m still trying to find the semantic difference (in relation to the repeated calculation of a target position) of those two behavior trees above. At least I think that I was able to answer one my questions on my own: Do orange coloured nodes mean that they were setup with “Repeat” to either “Until Failure”, “Until Success” or “Forever”?
March 11, 2022 at 1:47 pm #9616For coloring:
Red means fail
Yellow means running
Green means successorange means success or failure and repeated - you may not know why (something we can possibly change)
March 15, 2022 at 8:53 pm #9916I think, I finally found the answer to the issue myself. The root for my problems is the “Detect” Action because its “Mount Point Variable” will be set even if it didn’t find an aspect (i.e. it will be set to ‘null’) which is something I wasn’t expecting since the Wiki reads: “If an Aspect is detected, the Detect node will assign up to three variables in AI Working Memory”… So IF an aspect is detected. Anyway, I’m glad I found it.
Please, add this information to the Wiki as I think this is a really important information!
Greetings
BrightBit-
This reply was modified 1 year, 10 months ago by
BrightBit.
March 16, 2022 at 2:40 pm #9948Thanks BrightBit. Yes, the Detect action will assign a value to the variables you specify whenever it runs. If the Aspect is not detected, you will get a null value.
I’ll ask someone to update the wiki.
March 17, 2022 at 5:22 pm #10035Thanks BrightBit! Prime I’ll update the wiki to clearly note this.
-
This topic was modified 1 year, 11 months ago by
-
AuthorPosts
You must be logged in to reply to this topic.