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 2 years ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #9034

    BrightBit
    Participant

    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 2 years, 1 month ago by  BrightBit.
    #9055

    prime
    Keymaster

    put 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)
    —— IdleState

    #9079

    BrightBit
    Participant

    Hi 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:

    #9086

    BrightBit
    Participant

    I 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?

    #9112

    prime
    Keymaster

    What are the success/failure conditions on your parallel (named “parallel”)?

    #9115

    BrightBit
    Participant

    The conditions for the parallel in my solution are:

    Fail: any
    Succeed: all

    #9136

    BrightBit
    Participant

    In 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>
    
    #9361

    BrightBit
    Participant

    I’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”?

    #9616

    prime
    Keymaster

    For coloring:

    Red means fail
    Yellow means running
    Green means success

    orange means success or failure and repeated - you may not know why (something we can possibly change)

    #9916

    BrightBit
    Participant

    I 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 2 years ago by  BrightBit.
    #9948

    prime
    Keymaster

    Thanks 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.

    #10035

    CodersExpo
    Participant

    Thanks BrightBit! Prime I’ll update the wiki to clearly note this.

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.