playMaker

Author Topic: "Noise" Action  (Read 2720 times)

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
    • View Profile
"Noise" Action
« on: April 03, 2011, 01:49:45 AM »
In 3dsmax, the 3D package I use in my work, there's a great controller called a "noise float". Basically what I would want is to be able to control a value over time in an interpolated random fashion similar to the screen-shot I posted below. If this could be implemented as a float and maybe int (though I guess you could use convert the float to int if you needed to) that would be a bonus.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 12342
  • Official Playmaker Support
    • View Profile
Re: "Noise" Action
« Reply #1 on: April 04, 2011, 10:52:28 PM »
Hi,

 Ok, I have put together a simple PerlinNoise action that should get you started. It doesn't have all the fanciness of the max noise generator, tho. I have some code that lerp the noise for some similar ramp in and out effect, but that would complicate this action unnecessarily for now.  It outputs a float ranging from 0 to 1. You can then do whatever you want with it and convert it to int or multiply it etc etc.

 Hope you find it useful :)

 Bye,

 Jean



Code: [Select]
/// <summary>
///
/// Jean Fabre April 2011
/// http://www.fabrejean.net
///
/// More infos on the playmaker api for actions: https://hutonggames.fogbugz.com/default.asp?W351
///
/// This action uses PerlinNoise generator with a random seed on the x axis and an animated value on the y axis.
///
/// </summary>
using UnityEngine;


namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Effects)]
[Tooltip("PerlinNoise action")]
public class PerlinNoise : FsmStateAction {

[RequiredField]
[Tooltip("PerlinNoise animation speed")]
public FsmFloat speed;

[RequiredField]
[Tooltip("the actual PerlinNoise result ranging from 0 to 1")]
[UIHint(UIHint.Variable)]
public FsmFloat perlinNoise;

[Tooltip("If set to false, will not animate over time")]
public bool everyFrame;

/// <summary>
/// randomness for the perlinnoise.
/// </summary>
private float _seed;

/// <summary>
/// Reset all values
/// </summary>
public override void Reset()
{

_seed = Random.Range(0f, 65535f);
speed = new FsmFloat();
speed.Value = 1f;
perlinNoise= null;
everyFrame = true;

}// Reset

/// <summary>
/// Compute the perlinNoise and finish the action if only supposed to run once.
/// <see cref="everyFrame"/>
/// </summary>
public override void OnEnter()
{

ComputePerlinNoise();

if (!everyFrame)
Finish();

}// OnEnter


/// <summary>
/// If the action is suppose to run every frame, we compute the noise here
/// <see cref="everyFrame"/>
/// </summary>
public override void OnUpdate()
{

ComputePerlinNoise();

}// OnUpdate


/// <summary>
/// Compute and store the current perlin noise.
/// </summary>
private void ComputePerlinNoise(){

perlinNoise.Value = Mathf.PerlinNoise(_seed, speed.Value*Time.time);

}// ComputePerlinNoise

}// PerlinNoise
}// namespace HutongGames.PlayMaker.Actions
« Last Edit: June 24, 2013, 10:53:39 PM by jeanfabre »

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
    • View Profile
Re: "Noise" Action
« Reply #2 on: April 04, 2011, 11:07:34 PM »
Thank you very much, this will come very handy! That was very nice of you.

Don't let this make me sound ungrateful, but if maybe the developer would want to take it a step further and integrate all the functionality of the max controller that would be even more amazing.

Again, thank you and I hope karma pays you back (or if you are a starving student or something I'll paypal you a donation!). I am sure for now I can fade it in and out using other actions. Going to go play with this now.