News Forums Troubleshooting Cant toggle visual sensors through Expression

Tagged: , ,

This topic contains 4 replies, has 2 voices, and was last updated by  calebm 11 hours ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30935

    jamoy1993
    Participant

    Hello i basically want to toggle a visual sensor called CD (ChaseDistance) to detect the player if he hides within a specific distance for the ai to seek them out. I only want this to be active once the ai spots the player. However i am having difficullties working out what to put as the expression to activate / deactivate the ai’s visual sensor. Ive tryed things like

    CD.IsActive = false
    CD.isActive = false
    CD.isactive = false
    CD._IsActive = false
    CD.IsActive = "false" 

    blah blah blah…

    What am i doing wrong?

    • This topic was modified 4 days, 23 hours ago by  jamoy1993. Reason: Corection
    #31006

    calebm
    Participant

    You might not have a valid reference to the sensor. You can get the sensor from the AI component.

    Here is some example code for enabling/disabling from within a custom RAIN action (in C#):

        
    public override void Start(AI ai)
    {
    	// Two ways of disabling
    	ai.Senses.DisableSensor("CD");
    	ai.Senses.GetSensor("CD").IsActive = false;
    	// This to enable again
    	ai.Senses.EnableSensor("CD");
    }
    

    I think you could put this code anywhere that you have a reference to the AI component, not just in a custom action. The Javascript version would be similar.

    Also, rather than enabling and disabling the sensor, you could setup the behavior tree in such a way that it only checks the sensor if the AI has already seen the player. My guess is you would still have the performance hit from this sensor running every update though, so maybe that’s why you’re trying to disable the sensor?

    • This reply was modified 3 days, 21 hours ago by  calebm. Reason: Format looked bad and a correction
    #31008

    calebm
    Participant

    I’m sorry, I didn’t read your post very well. I notice now that you’re trying to use an expression, so disregard that last post (unless you want to do it through scripts).

    I think expressions only show variables that are in the AIs memory and sensors are not in memory, so you won’t be able to use an expression until you put it in memory. But, why bother when you can just design your tree better?

    Because the sensor only gets checked by your detect node in the behavior tree, I think the right solution to your problem is to design your behavior tree to only detect things on that sensor if some other variable (like “hasSpottedPlayer”) is true.

    That would require a selector node, then a constraint node under that to check if the AI has spotted the player, then a node under that to actually detect things on the CD sensor. Then, in this same part of the tree, you can have action nodes for going after the player based on input from the CD sensor.

    #31017

    jamoy1993
    Participant

    Also, rather than enabling and disabling the sensor, you could setup the behavior tree in such a way that it only checks the sensor if the AI has already seen the player. My guess is you would still have the performance hit from this sensor running every update though, so maybe that’s why you’re trying to disable the sensor?

    i basically tryed this out of curiousity. But basically i want do disable it as im just building basic ai at the moment. The reason i want to disable it is because its a full 360 sensor for when the player has been spotted. This allows my AI to chase them throughout the part of my scene.

    I will be using scripts more as i develop my AI. I am fluent in C# and Java as they are practically the same, i self taught my self java from C# by following a tutorial.

    #31167

    calebm
    Participant

    One more thing. On the bottom of this wiki page is code for a sensor extension that toggles between two sensors based on distance. It might be something you want to look at.

    • This reply was modified 10 hours, 59 minutes ago by  calebm.
Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.