• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GreenLimeLight · Jan 04, 2012 at 05:11 AM · movementontriggerentercoroutinesslow

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! :)

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image syclamoth · Jan 04, 2012 at 05:29 AM 0
Share

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.).

avatar image GreenLimeLight · Jan 10, 2012 at 01:29 PM 0
Share

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. :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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)
Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GreenLimeLight · Jan 10, 2012 at 01:31 PM 0
Share

How do I go about starting on this control only script?

avatar image roamcel · Jan 10, 2012 at 05:53 PM 0
Share

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.

avatar image GreenLimeLight · Jan 12, 2012 at 06:26 AM 0
Share

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?

avatar image roamcel · Jan 12, 2012 at 06:53 AM 0
Share

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.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

onTriggerEnter only triggers when the gameobject its shall hit moves. 1 Answer

Moving a object when player enters trigger and play a sound 1 Answer

Slow camera move speed? 2 Answers

On Trigger Enter no longer works? long delay to activate 2 Answers

The sphere goes Slow 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges