News Forums RAIN General Discussion and Troubleshooting Detecting out of range

This topic contains 2 replies, has 2 voices, and was last updated by  prime 1 year, 8 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #4731


    I just started using RAIN and I’m really impressed so far. Great job!
    However, I’m having a problem. I set up an AI unit that stands still on the map and chases the player when it detects him. The player has an Entity component and an Aspect called Player. The AI has a Visual sensor, and its tree is like this:
    - detect (Detects Player entity and stores the result in playerPosition)
    - move (Moves towards playerPosition)
    The player runs faster than the AI, so it’s possible for him to escape. I was expecting that when the player got out of the range of the sensor of the AI, the AI would stop chasing the player. However, this dosen’t happen. Once the AI detects the player, it AI knows where the player is even when he is not inside the AI’s sense range, so it keeps chasing him forever.
    Any idea of what I can be doing wrong?
    Thanks for your help.



    I just found the solution. It seems that detect and move nodes do not return success or failure (I believe they return running). Because of this, the previous tree never updated. The solution I found is the following:
    PAR (fail -> all, succeed -> any)
    - detect (Detects Player entity and stores the result in playerPosition)
    - move (Moves towards playerPosition)
    - expression (expression = true)
    Now, when the player is out of range of the AI sensor, the AI stops following the player.
    Is this the correct solution or is there a more elegant one?



    Detect nodes always return Success if they detect a matching Aspect, and Failure if they do not.

    Move nodes always return Failure if they have no target, or if they can’t compute a path, Success if they arrive within Close Enough Distance to the target, and Running if they are still trying to move toward the target.

    I suspect the problem was that the Detect node Succeeded in your Parallel, but the Move node did not, and the Parallel was set to Succeed on All. So your Detect would never try again after it detected the Player, and would never reset the variable when it was out of range.

    It is more common to change the Detect node to repeat forever, and then let the Parallel succeed on Any.

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

You must be logged in to reply to this topic.