Tesla Tower Trap

Afternoon to all programming evangelists out there! I have some issues with this “trap” I’m working with currently.

When the player steps into the trigger, it will cause a reaction, in which four “tesla towers” would appear from the ground and form some sort of electric barrier. (The trigger will probably be in the middle of this entire trap). In a way, they form electric fences. Once that happens, the players are left with 2 options. Either they do not do anything and they’ll be stuck in that confined area for a set amount of time (let’s say 5 seconds) or attempt to break through the electric barrier/fence and get damage plus a slow. (let’s say 10/100 dps, and a 25% speed reduction, plus it takes 2 - 3 seconds to break through.)

So, my question is how do I go about starting this? I’d only know that I’d have to start with an OnTriggerEnter, and I’m clueless on how to continue afterwards. Thus it would be great if I could get any suggestions/solutions to get started on this. Thank you very much in advance (and have a nice Tues/Wed!).

[Edit #01] Heyhey, everyone!

My current script for the Tesla Tower Trap (TTT). Once a Player Tag is detected in the Trigger, the TTT will play its animation of being raised from the floor. Electric fences will be switched on once the animation completes between four floating orbs (North, South, East, West).

In between these orbs, in the place of the electric fences are Triggers that I want to deal Damage per Second (DPS) and causes Speed Reduction to the Player. Anyone has any idea how I can start off? Thank you very much! :slight_smile:

[Edit #02] Heyhey, everyonce!

The Tesla Trap is finally working! Hee, thanks everyone. However, the DPS is still an issue. I’ve read online about people using InvokeRepeating, but it doesn’t affect multiple users. My original idea was that this trap is able to affect multiple users, regardless of when they enter the trap. Does anyone has an idea how I can still deal DPS while the players are slowed in the electric fence? I’m using OnTriggerEnter, OnTriggerStay and OnTriggerExit currently.

Detailed explanation: OnTriggerEnter, my user’s speed is reduced to 0.1. OnTriggerStay, my user’s speed still remains at 0.1. Only OnTriggerExit, my user’s speed returns to 1, and it receives instant damage. What I want to do, however, is upon OnTriggerStay, DPS is dealt to the user, and once OnTriggerExit, everything returns to normal (Speed returns to 1, and user stop receiving damage).

Thank you for any help rendered! :slight_smile:

You have several important design issues here, however there's a rough draft:

  • create a control only script, that regulates character movement
  • when the trigger activates, play the forward trap 'animation' (or whatever puts the trap in place), make your 'trap script' fetch that control script from the collision, and use the "invoke" function to call a reverse animation on the trap, after the 5 second wait
  • put other colliders on the fences, and be sure that there's a trigger event for them too, if the trigger activates, use the control script you fetched earlier to change the hitpoints and speed of the character (you can easily do this by a setter and getter in the class)