playMaker

Author Topic: Smooth value change?  (Read 2632 times)

MajorIdea

  • Full Member
  • ***
  • Posts: 131
Smooth value change?
« on: January 20, 2013, 06:04:24 PM »
Is there a way of smoothly changing the intensity of a light.

And what about smoothly fade between two materials or material textures?

Thanks...

Horror

  • Junior Playmaker
  • **
  • Posts: 79
Re: Smooth value change?
« Reply #1 on: January 20, 2013, 09:48:50 PM »
Not sure about the materials but I have used playMaker to smoothly change light intensity before. Here's what I did to create a pulsating light:
(Sorry, I wasn't expecting it to be this long!)

1. Create an FSM with a float variable to store the lights intensity value. Call the variable lightIntensity and set its value to 1.0

2. Rename the default start node "State 1" to something like AddLight. Drop a Float Add action onto it and set its float variable to the lightIntensity variable you created. In the Add field set a value like 0.05; this is how much the brightness will be incremented by every time the action is visited. Also add a Wait action to this node and set it's value to something low like 0.05; Set a FINISH event for it. The wait will determine how quickly the the light will pulsate.

3. Create another node (Call it ApplyLight) and hook the AddLight node's Finished output into it. Add a Set Light Intensity action to your ApplyLight node and set the Value to the lightIntensity variable. Also add a Float Compare action and set its Float 1 field to the lightIntensity variable; set the Float 2 variable to the maximum intensity you want the light to reach (say 2.0). Create a TRUE event and a FALSE event and add them both as outputs for your ApplyLight node; Link the FALSE output back to your AddLight node that you created in Step 2. Now Add a Float Compare action to your AddLight node and set Equal to TRUE, Less Than to FALSE, and Greater Than to TRUE.

***
What your ApplyLight node is doing is firstly to apply the lightIntensity value to your light. It then checks if lightIntensity is equal to or greater than 2.0 - if it is not, then it will output FALSE and jump back to your AddLight Node, which will then increment the lightIntensity by another 0.05 before firing the FINISH event back to your ApplyLight node, which will then apply the lightIntensity value to your light and again check if lightIntensity equals 2.0. Once it equals 2.0 it will fire the TRUE event output.
***

4. Duplicate your AddLight node (call it SubtractLight) and hook the TRUE event output from your ApplyLight node into it. This node works exactly the same as your AddLight node, only this time your Float Add action value will be set to -0.05 to subtract the light's intensity.

5. Finally duplicate your ApplyLight node (Call it ApplyLight2) and hook the FINISH event output from your SubtractLight node into it. Change the Float 2 variable on your Float Compare Action to 1.0 (this is the minimum intensity for the light). Change Less Than to TRUE and Greater Than to FALSE. Here we are checking if lightIntensity is greater than 1.0, and if it is, then go back to SubtractLight. Finally, hook the FALSE event output back to your SubtractLight node and the TRUE event output back to your original AddLight node.

Now you should have an endlessly pulsating light.