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.
-
AuthorPosts
-
November 25, 2022 at 3:42 pm #5618
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 馃槈
November 25, 2022 at 5:30 pm #5624Lots 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, likerig.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.November 26, 2022 at 11:39 am #5640Thank 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
November 26, 2022 at 10:28 pm #5650Line 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.
November 27, 2022 at 9:37 am #5658Yes, 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
路WaterThere鈥檚 no option to permit ignoring the terrain. Maybe creating a custom action to overide the Require Line of Sight?
November 27, 2022 at 2:56 pm #5664You can add more layers through Unity and assign the terrain to its own layer. RAIN will pick up any new layers you define automatically.
-
AuthorPosts
You must be logged in to reply to this topic.