Hi there. I have been experimenting with a makeshift line of sight mechanic in a 3D first-person game where I use an "On Enter" trigger to activate specific actions in an NPC. It all seems to work fine for the most part, I've ran into an issue where the trigger goes through walls and activates the ActionList when the NPC is on the other side of a wall. (I know it's not an issue, it's as intended) My question is, is there a way to make the trigger collider stop when it comes into contact with a different collider? - I'm using tags to trigger the NPC ActionList.
As usual, thank you in advance for any help.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
You can try using a separate Trigger component on the same object that reacts to objects with a different Tag, but it won't account for the distance.
Have you tried the Physics: Raycast Action? It allows you to detect objects along a given direction and pass them into GameObject parameters.
Otherwise, a short script to handle detection may be best.
Hi Chris, thanks for the quick reply. I tried with Raycast but wasn't too successfull, unless I'm missing something. I also tried using a custom script but it was also not great. Is there a way to make a custom action that check's for a layer/tag, similarly to variable true/false? Actually, I guess Raycast does exactly that? Is there a tutorial or an example of it being in use somewhere on the forum? I'm looking at the manual, and I'm not exactly sure how to trigger the ActionList for a Collision Cube. Do I create a trigger and run the actionlist inside the trigger and call the Collision cube that way?
The Object: Check tag Action is available to check object tags, but I'm not sure what you're trying to "call" with the Collision cube.
I think this topic might benefit a bit more zoomed out. Can you share more details on the underlying situation, with screenshots?
Sorry. Here's what I'm trying to achieve. I've added a trigger OnContinous and On Exit to a flashlight that I can enable/disable from my inventory. When I enable the light a particular NPC stops following you. When you move the light away (On Exit), the variable = false and the NPC starts following you again. I was able to achieve all of this easily. The issue I'm having is the triggers go through walls and they cause the NPC to stop instantly. I need the trigger to only affect the NPC when there are no other props or walls in font. That's about it.
Sounds like the Raycast Action should indeed be useful here - if you use it at the start of your OnContinuous logic, you can check if the raycast-detected object matches that detected by the Trigger. If the two don't match, end the ActionList.