Lately, I’ve been thinking about a more generic trigger system, and I wanted to get some feedback before I start coding, so read this and slam it.
We have some Trigger components - these are small scripts that react to something in the world, and sends out a trigger message to a target object. We then have some Actuators - these accept the trigger message and do something.
Triggers would be:
Trigger - sends a message on an OnTriggerEnetered event
CollisionTrigger - sends trigger messages when something collides.
KeyboardTrigger - sends trigger messages when the user presses a key.
Timing trigger - sends a trigger message after some time
All triggers can take multiple hits to activate, and can either send out a message EACH time they’re triggered or just once. They can optionally untrigger when the condition is no longer true. They BroadcastMessage to a target object, so any triggers in a hierarchy can be activated/deactivated.
Now for Actuators:
Rotator - make something spin
LookAt - looks at something
LightFlicker - make a light flicker
PlayAnimation - plays a named animation when triggered
EmitParticles - Emits some particles when triggered
Spawn - Instantiates a prefab when triggered
PlaySound - plays an audio source when triggered.
All actuators have On/Off states. PlayAnimation, LightFlicker, Rotation can have fadeIn fadeOut times to animate something turning on and off (e.g. lightflicker can make it look cool when the light gets turned off).
Different actuators can have a bunch of extra properties. I’ll get to those as I get along…
I’m looking into making this be part of the Standard Assets, so I want it to be as good as possible. Then, BruceGregory will write some tutorials on how to use them. So, tell me what you think…
These are almost better than I hoped for. What about a mouse trigger, though? It’s O.K. if you don’t do a mouse trigger, since the other stuff looks so good, but it would be the bees’ knees if you did. I’m a little unclear about the “light flicker” - can this just act also as a simple light switch? What happens when 2 triggers are fired simultaneously, (i.e. first or third person movement by cursor and an animation of the same character by cursor keystroke at the same time)?
Correct me if I’m wrong, but it seems like these functions would enable nearly all the aspects of a game to completed by a non-coder. The only thing I can’t immediately perceive is whether a scoring system or a health system could be created with these, alone. If so, this would put Unity in an additional league to its already excellent status. You’ll also make a lot more people happy, as well. You’ve definitely got my support on this one.
MouseTrigger I just plain forgot. Of course it’s in there
Health systems would be a bit harder, though… (esp. as things do more or less damage). As would ammo counters etc… these things mostly work for on/off kind of things (although you could animate the switches)…
At some point we definately should look into doing some PlayerWithMountableWeapons kind of thing… We have done a few weapons/healts systems, but just never one we were really happy with.
As for the thanks, well, I haven’t written it yet, have I?
Oh, you will. . . . you will. If you start releasing these one at a time, I can start producing some QuickTime demonstrations for them as they get done, just to help everybody jump on these things ASAP.
Was thinking that we broadcast the trigger, so you’d do parenting for that. If you want more effects, you can have many triggers that do the same thing, though…
Keyboard would probably have a bunch of settings (key-down, key-up, key-down-up, deTrigger after keyup, etc).
Most triggers that react to a boolean state should support some of these settings…
Sounds awesome.
Don’t go too far, or I’ll don’t need to code at all! Where’s the fun in that!
I think Unity should handle general situations and provide helpers for those (e.g particles, parent/child relation, etc) but not stuff that are tied to a certain genre or situation. A FPSwalker I can understand, it can help to view the world, but a health system should be coded IMHO.
For a trigger it would be nice to able to have a Pulse as an option (just a term I’ve come up with), throught the inspector it can be fed with an array of values.
This would mean:
Pulse #1 to #6 are looped through. From top to bottom.
A pulse is in fact a trigger. #1 triggers after 0 gametime. Then at 100 gametime, it triggers again. Then 90 game time later, again…etc. This all is executed 2 times (trigger loop value)
and then it stops “pulsing” until it is re-activated.
Trigger loop value 0 = no loop (no pulse).
Trigger loop value -1 = infinite (pulse as long as object exists)
When clickin
This pulse can then be attached to creating an instance (e.g a bullet): imagine a monster shooting bullets in some kind of rythm! This is the pulse at work.
Another component: distance trigger.
Gets the distance of object - of a certain kind (e.g distance to our main game hero). When the distance exceeds a value that can be set in the inspector, it triggers.