News Forums RAIN General Discussion and Troubleshooting Line of sight tricks

This topic contains 4 replies, has 3 voices, and was last updated by  Snuffles10155 1 year, 10 months ago.

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

    Snuffles10155
    Participant

    I’m currently trying to setup my ai so that if the player is in a bush the ai cannot see the player. While line of sight works well it requires a collider to stop it from being successful. I have tried making a cube that is invisible to everything and the collider for it is set to ignore physics for default layer on my objects so players and ai can walk through it however this means the AI’s line of sight goes through it too… I am close but I must be missing something here. Any ideas ? What will be great if this works is you can hide in a bush, but if the ai enters the bush they will see you!

    #8342

    marcfielding
    Participant

    Well Prime will probably be able to answer this better but here’s how I would do it based on my understanding of Rain, again note I may not be giving you the “best” way to do this.

    1) You say “bush” I assume its a prefab? Why not just add a collider to the bush and set it to be a trigger that way you can walk through it, I don’t know if rain still counts this as blocking the line of sight though….

    2) If Rain doesn’t block trigger colliders from line of site you could set a variable on your player for when they are inside the collider as being “hidden” then in your AI you setup an action when a player is detected and if they have the hidden variable set to true then your AI can ignore them.

    Good luck!

    Marc

    #8394

    prime
    Keymaster

    Line of sight calculations are done using unity raycasting. Raycasts colliding with triggers is a option you set in your physics settings. Regardless, it is probably unnecessary, since you can just use regular colliders with layers and collisions set appropriately.

    The AI LoS is based on the mask that you set on the sensor itself. In other words, setting the collider to not collide with the default layer has no impact on whether the AI can see it. Just put the bush collider in a special layer that doesn’t collide with anything but itself. Then set the sensor mask to include that layer. Should work…

    #8399

    marcfielding
    Participant

    Hehe, see told you he’d have a better way! I was actually just sitting here playing with a bush/hide scenario to figure out a good way of doing it, I keep forgetting about layers!

    #8426

    Snuffles10155
    Participant

    Hey prime, that did the trick! I had some trouble for ages where my player would keep colliding, but after investing my UFPS scripts that im using for the player it was placing the player in a new layer at runtime so after adding that to my layers list and disabling collision everyone and everything can pass through the LOS blocker, AI now behaves like I wanted to :)

    Prime to the rescue again it seems! I can see myself crediting you in our game when its done for all the useful help you give :)

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

You must be logged in to reply to this topic.