playMaker

Author Topic: Creating a dimmer button on a light  (Read 749 times)

Bcurtis

  • Playmaker Newbie
  • *
  • Posts: 1
Creating a dimmer button on a light
« on: June 20, 2019, 03:49:16 PM »
Hi,

I have this working but I think it's probably horribly inefficient and be done inside one FSM.

I have one FSM with two states. Lights on and Lights off. On entering either state I Animate Float a global 'Light Intensity' variable, and then a Trigger Event switches states On Trigger Enter.

I have another FSM with one state only that sets the light intensity each frame based on the Light Intensity global variable.

Can/Should this be done inside one FSM or have I done it in the most performant way? I'm planning to use the same method to turn on and off a fan sound by animating volume so I'd like to know if this is generally the way to do things!
« Last Edit: June 20, 2019, 03:56:54 PM by Bcurtis »

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Creating a dimmer button on a light
« Reply #1 on: June 20, 2019, 04:59:54 PM »
Don’t worry about performance just yet. If your setup will be used in the order of magnitude of a thousand times, then maybe.

Other than that, totally depends on what you want to do.

You could do it without the global variable, and just one FSM. On Trigger Enter animate the float and set it in one state, and when dimming is complete go into an empty “done” state. I don’t know the actions you use, whether they have finish conditions etc, but you can easily float compare every frame until the target value is reached.

Duplicate the state with the actions, change the OnTrigger global event (e.g. on exist) and set another float target value (when one dims to on, then this goes to off). Again, when target value is reached go to the (same) “done” empty state.