playMaker

Author Topic: Offset Float By Percentage  (Read 3310 times)

Flying Robot

  • Sr. Member
  • ****
  • Posts: 293
  • Od ton yebo redro
    • Flying Robot Studios
Offset Float By Percentage
« on: September 16, 2013, 09:03:35 AM »
Hi,

This would be my first PlayMaker custom action. Let me know if you like it.

It takes a float (input) and offsets its value within a random range of a percentage (input) of it's value.

May come useful if you want to add a little random variation to a float value.
« Last Edit: September 18, 2013, 02:19:30 AM by Flying Robot »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Offset Float By Percentage
« Reply #1 on: September 17, 2013, 02:50:44 AM »
Hi,

 Nice! You got action writing standard  well executed, well done.

I would add a small feature: everyframe. So thyt this action can generate a random float in that range constantly, might be useful for such thing as noisy animations and stuff.

bye,

 Jean

Flying Robot

  • Sr. Member
  • ****
  • Posts: 293
  • Od ton yebo redro
    • Flying Robot Studios
Re: Offset Float By Percentage
« Reply #2 on: September 18, 2013, 02:20:32 AM »
Thanks Jean,

I've Updated the attachment with everyframe option.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Offset Float By Percentage
« Reply #3 on: September 18, 2013, 02:28:13 AM »
Hi,

 Cool.

one important advice as a general way of scripting. Avoid duplicating code. Instead, create a new method ( ie "ComputeRandom()") where you will have your code, and call that method form the onEnter and OnUpdate methods. This way you only have one set of commands for your feature. In more complex programming this is essential to not fall into bad bugs and totally painful refactoring. In our case, it's minor, but still, if you need to edit this featurem you will have to do it twice, and you may forget or make a small typo and then it will work differently is eveyframe is checked than if not...

Bye,

 Jean

Flying Robot

  • Sr. Member
  • ****
  • Posts: 293
  • Od ton yebo redro
    • Flying Robot Studios
Re: Offset Float By Percentage
« Reply #4 on: September 18, 2013, 03:15:02 AM »
Thanks Jean,

I'll follow you suggestions and pack the code into a new method and call it from the enter or update.

4ppleseed

  • Full Member
  • ***
  • Posts: 226
Re: Offset Float By Percentage
« Reply #5 on: February 10, 2015, 05:02:38 PM »
There's an error in the Tooltip section for this action. Can it be fixed please? :)