playMaker

Author Topic: Can I add per second to any playmaker action?  (Read 3799 times)

QFGlenn

  • Playmaker Newbie
  • *
  • Posts: 30
Can I add per second to any playmaker action?
« on: May 10, 2016, 08:10:24 PM »
Hi. I want my playmaker FSM to get the value of a float every few seconds or so while waiting for an event to be remotely sent. Every Frame is a heavy operation and I only use it when I know it won't be active long to reduce any bugs.

Some playmaker actions after every frame have another checkbox for per second this sounds ideal to me.

I thought about adding in a wait state but wouldn't adding the transfer cause it to occasionally miss the sent event?

What I'm wondering is: Is the per second functionality just a block of code I could copy paste into other playmaker actions? And why isn't there an every X frames option???

dudebxl

  • Hero Member
  • *****
  • Posts: 602
Re: Can I add per second to any playmaker action?
« Reply #1 on: May 10, 2016, 09:28:09 PM »
use wait action.

QFGlenn

  • Playmaker Newbie
  • *
  • Posts: 30
Re: Can I add per second to any playmaker action?
« Reply #2 on: May 10, 2016, 10:39:09 PM »
I know about wait. I've used wait. But I have to go from wait to another state I can't just delay and replay the state.

UE4 Blueprints have delay, why not Playmaker?

joduffy

  • Full Member
  • ***
  • Posts: 121
  • Here to help
    • Online Playmaker Courses
Re: Can I add per second to any playmaker action?
« Reply #3 on: May 10, 2016, 11:41:07 PM »
Hi dude,

I looked into this for you and I think I found a way for you to edit the FSM's. I would suggest making a copy though and having it as your own custom FSM.

So I looked at the Rotate action. It has the perSecond what you are after. It also has different update options.

Code: [Select]

[Tooltip("Rotate over one second")]
public bool perSecond;

[Tooltip("Repeat every frame.")]
public bool everyFrame;

[Tooltip("Perform the rotation in LateUpdate. This is useful if you want to override the rotation of objects that are animated or otherwise rotated in Update.")]
public bool lateUpdate;

[Tooltip("Perform the rotation in FixedUpdate. This is useful when working with rigid bodies and physics.")]
public bool fixedUpdate;

Then for each of these update options it calls a method in the script called DoRotate:

Code: [Select]

void DoRotate()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null)
{
return;
}

// Use vector if specified

var rotate = vector.IsNone ? new Vector3(xAngle.Value, yAngle.Value, zAngle.Value) : vector.Value;

// override any axis

if (!xAngle.IsNone) rotate.x = xAngle.Value;
if (!yAngle.IsNone) rotate.y = yAngle.Value;
if (!zAngle.IsNone) rotate.z = zAngle.Value;

// apply

if (!perSecond)
{
go.transform.Rotate(rotate, space);
}
else
{
go.transform.Rotate(rotate * Time.deltaTime, space);
}
}

So the bit your are interested in is perSecond boolean and the last bit from the DoRotate method:

Code: [Select]

if (!perSecond)
{
go.transform.Rotate(rotate, space);
}
else
{
go.transform.Rotate(rotate * Time.deltaTime, space);
}

What it does is check to see if the tickbox or boolean is true, if it is try it will do the Time.delta or else part of the if statement. If it is false, it will do the if part - (rotate, space)

If you are new to programming or want an example FSM let me know and I will try and help you out.
- Jonathan

Online Playmaker Courses available at:
http://courses.jonathanoduffy.com

“I want the world to be a better place because I was here.”  -  Will Smith

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Can I add per second to any playmaker action?
« Reply #4 on: May 11, 2016, 01:37:25 AM »
Hi,
maybe you can use wait and loop back to the same state?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Can I add per second to any playmaker action?
« Reply #5 on: May 11, 2016, 02:57:04 PM »
Quote
I thought about adding in a wait state but wouldn't adding the transfer cause it to occasionally miss the sent event?

A Wait action sounds like the way to go. Just loop back into the same state as djaydino suggested. It will respond to events while waiting.

If you want to use a separate Wait state you could add the event to that state also, or use a global transition to react to the event no matter what state you're in.

The per second option in some actions doesn't wait for a second. It adjusts certain math operations done every frame so they're frame rate independent. So you're specifying a parameter in units per second, instead of units per frame (which would behave differently if your frame rate changes). Behind the scenes it multiplies the relevant parameters by Time.deltaTime.
« Last Edit: May 11, 2016, 02:59:32 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Can I add per second to any playmaker action?
« Reply #6 on: May 11, 2016, 03:07:35 PM »
Or use a Send Event with a delay to loop the state.

EDIT: Added an animated gif (click to play).
« Last Edit: May 11, 2016, 03:15:09 PM by Alex Chouls »