- Home /
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! :)
[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! :)
Look at Coroutines. They're the key to how I would go about solving this one. Other than that, I'd look at designing a centralised 'status effects' controller for the player to manage damage over time / slowdown etc. This would also manage special effects (lightning etc.).
Hey, thanks. I've looked at Coroutines and it's solved the problem of the animation part. I've edited the question information for the second problem, which is the DPS and Speed Reduction part. :)
Answer by roamcel · Jan 04, 2012 at 07:10 AM
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)
How do I go about starting on this control only script?
create a script, and put all character movement related variables and functions there. Usually, since the character moves through the Update function, to disable character movement you just disable the script.
Alright, thanks! It works fine now, instant damage and slow. :) However, is there a way to do damage per second, to multiple users at once? I've checked online and most uses InvokeRepeating, but InvokeRepeating will only deal damage to one user, right?
InvokeRepeating doesn't carry parameters to the called function, but inside that function you can do whatever you please. So for example if you had an array of transforms that hold the transforms of all players inside the trap boundaries, you'd be set. I admit however that this can be implemented in many ways, and none is easy.