Best way to implement a trap that activates as player runs past it?
Hey, this is my first question on this community forum and I'm sorry if something like this has been answered before but I couldn't find it. I'm looking forward to seeing what you guys suggest.
So I'm having issues figuring out how to implement a trap in my project that would slow down a chasing AI as they walk through it. From a design perspective the trap would be something like a stack of logs, or barrels in an alleyway and as the player runs through with AI chasing him there would be a chance for him to activate the trap while next to it. As the player runs on the AI movement speed would get reduced or something along that idea.
Let's go with the idea that its a few barrels stacked on top of each other. It would be ideal if the trap wouldn't have to be animated. In my mind this would work by applying a force to the barrels after a key press so that they fall and roll around on the ground for a second before stopping. They wouldn't have a collider so the AI can still walk through them but at a lower movement speed.
Answer by LK84 · Jan 09, 2017 at 04:10 PM
use a trigger and the OnTriggerEnter() function to activate the trap https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html