News Forums RAIN General Discussion and Troubleshooting Custom Action to stop the AI when the player is looking at it

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

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5618

    Loktar
    Participant

    Hello everybody, I鈥檝e been working with this powerful tool for like 2 weeks, and I鈥檓 absolutelly astonished with it, really, great job. But now comes my problem, I鈥檓 trying to create a custom action in which, the AI can only move to me when I鈥檓 not looking a it. Therefore, when I face it, it should stop moving and start just facing me, but I鈥檓 having problems by creating it, any idea? One of my problems is that I don鈥檛 know how to use the variable “Player” in the script, and I also don鈥檛 know how to detect if the AI is being looked by the player.

    Thanks in advance 馃槈

    #5624

    prime
    Keymaster

    Lots of ways to deal with it.
    - you could just have the player object tell the AI when it is looking at it. Have a component on the player that grabs the AI rig, then sets a variable in AI working memory, like

    rig.AI.WorkingMemory.SetItem("playerseesme", lookingAtAI);

    - you could put an aspect on the player, mounted near his eyes but outside his collider. Then use a sensor on the AI to with a Line of Sight check.
    - you could have the AI do a check on the forward angle of the player vs the angle from player to AI. If those are within some # of degrees, then set a variable to indicate “playerseesme” as above.

    #5640

    Loktar
    Participant

    Thank you very much! It worked for me, I just put a sphere with entity behind the player and activated the line of sight of a visual sensor, then, if I鈥檓 facing the NPC, it won鈥檛 move because the Player is blocking the vision of the NPC. BUT, this solution has a problem, which is that when the terrain blocks the vision of the NPC it also stops. So now I need to tell to the AI鈥檚 Line of Sight to ignore the terrain, how could that be done?

    Thanks again

    #5650

    prime
    Keymaster

    Line of sight has a layer mask. You could use that to ignore the terrain. However, why does the AI stop when the player is looking at them? If it is intended to mimic the AI鈥檚 awareness of the player, then allowing the terrain to block the line of sight seems like a good thing. If it is simply a game mechanic, then I wouldn鈥檛 use sensors for it, but instead write some custom logic, as in the 3rd option.

    #5658

    Loktar
    Participant

    Yes, I thought about using the Line of Sight Mask, but my problem is how to ignore just the terrain, because the options list of the line of sight mask is just:
    路Nothing
    路Everything
    路Default
    路TransparentFX
    路Ignore Raycast
    路Water

    There鈥檚 no option to permit ignoring the terrain. Maybe creating a custom action to overide the Require Line of Sight?

    #5664

    prime
    Keymaster

    You can add more layers through Unity and assign the terrain to its own layer. RAIN will pick up any new layers you define automatically.

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

You must be logged in to reply to this topic.