Playmaker Forum

PlayMaker Updates & Downloads => Share New Actions => Topic started by: BilbyCoder on April 02, 2011, 02:48:37 AM

Title: New Playmaker Action: Get Forward
Post by: BilbyCoder on April 02, 2011, 02:48:37 AM
And once again I've made a new action for my game Mushroom Harvest.

This time it simply fetches the forward vector of a Transform.

I actually need it to set up a raycast to find out if an object is in shadow (more specifically 9 raycasts to check the level of light based on bounding box and centre point).  That's going to be a fun action to write, and probably not posted here as it's game specific.

But here is my action for getting the forward vector.  Again, really simple but perhaps a useful copy/paste for someone.
Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

namespace DigitalBilby.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("Get's the Forward Vector of the Transform")]

public class GetForward : FsmStateAction
{
[RequiredField]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
public FsmVector3 vector;
[UIHint(UIHint.Variable)]
public FsmFloat x;
[UIHint(UIHint.Variable)]
public FsmFloat y;
[UIHint(UIHint.Variable)]
public FsmFloat z;
public bool everyFrame;

public override void Reset()
{
gameObject = null;
vector = null;
x = null;
y = null;
z = null;
everyFrame = false;
}

public override void OnEnter()
{
DoGetForward();

if (!everyFrame) Finish();
}

public override void OnUpdate()
{
DoGetForward();
}

void DoGetForward()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);

if (go == null) return;

Vector3 forwardAngle;

forwardAngle = go.transform.forward;

vector.Value = forwardAngle;
x.Value = forwardAngle.x;
y.Value = forwardAngle.y;
z.Value = forwardAngle.z;
}
}

}
Title: New Playmaker Action: Get Direction Vector (transform)
Post by: BilbyCoder on April 02, 2011, 04:28:25 AM
So, thinking about it I've made an alteration to the code.  Now it has a drop down menu to select either the Forward, Up or Right vectors of a transform.  That would be much more useful, espcecialy as it seems silly to have three almost identical actions when a simple switch statement can combine them all.

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

namespace DigitalBilby.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Transform)]
[Tooltip("Get's the Direction (Forward, Up, Right) Vector of the Transform")]

public class GetDirectionVector : FsmStateAction
{

public enum Direction
{
Forward, Up, Right
}

public Direction direction;


[RequiredField]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
public FsmVector3 vector;
[UIHint(UIHint.Variable)]
public FsmFloat x;
[UIHint(UIHint.Variable)]
public FsmFloat y;
[UIHint(UIHint.Variable)]
public FsmFloat z;
public bool everyFrame;

public override void Reset()
{
gameObject = null;
vector = null;
x = null;
y = null;
z = null;
direction = GetDirectionVector.Direction.Forward;
everyFrame = false;

}

public override void OnEnter()
{
DoGetForward();

if (!everyFrame) Finish();
}

public override void OnUpdate()
{
DoGetForward();
}

void DoGetForward()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);

if (go == null) return;

Vector3 directionVector = Vector3.zero;



switch (direction) {
case Direction.Forward:
directionVector = go.transform.forward;
break;
case Direction.Up:
directionVector = go.transform.up;
break;
case Direction.Right:
directionVector = go.transform.right;
break;
}

if (directionVector == Vector3.zero) return;

vector.Value = directionVector;
x.Value = directionVector.x;
y.Value = directionVector.y;
z.Value = directionVector.z;
}
}

}
Title: Re: New Playmaker Action: Get Forward
Post by: Alex Chouls on April 02, 2011, 12:55:06 PM
Excellent!

We're working on a forum category for Action Updates, New Actions, Sample Scenes, Templates... so we can push more frequent updates between Asset Store Updates... and also invite the community to help make Playmaker better!

That section will have some kind of waiver (e.g., Unless otherwise noted by the author, HutongGames reserves the right to include any posted action, sample, or template in a future Playmaker update). And we'll credit the original author.

Since we're behind the curve on that, I'd like to ask if we can include this action in a future Playmaker update?
Title: Re: New Playmaker Action: Get Forward
Post by: BilbyCoder on April 02, 2011, 04:57:22 PM
This action is generic and simple (but good for learning how to make new actions).

I BilbyCoder hereby release the above code under the whatever licence.  Do whatever you want  ;D

Title: Re: New Playmaker Action: Get Forward
Post by: tobbeo on April 03, 2011, 04:31:46 AM
Thanks Bilby!
Title: Re: New Playmaker Action: Get Forward
Post by: MaDDoX on April 06, 2011, 03:57:48 PM
We're working on a forum category for Action Updates, New Actions, Sample Scenes, Templates... so we can push more frequent updates between Asset Store Updates... and also invite the community to help make Playmaker better!
Hey, since the new forum section is now in place, shouldn't these two action threads be moved to it just to keep things nice and tidy?
Title: Re: New Playmaker Action: Get Forward
Post by: miketolsa on December 28, 2015, 05:51:10 AM
is it possible to make this action work .........

As I want the forward direction to make or add force to that direction .......
Title: Re: New Playmaker Action: Get Forward
Post by: JeremyP on January 22, 2016, 09:14:58 AM
It does work, as is, though you need to make some namespace/tooltip changes at the top of the code if I remember correctly.
Title: Re: New Playmaker Action: Get Forward
Post by: jeanfabre on February 02, 2016, 10:26:27 AM
Hi,

 Simply use the build in action "TransformDirection" the forward vector will be 0,0,1

http://docs.unity3d.ru/ScriptReference/Vector3-forward.html


Bye,

 Jean
Title: Re: New Playmaker Action: Get Forward
Post by: Fat Pug Studio on January 27, 2017, 07:23:07 AM
Hi, i can't find this action in the Ecosystem, is it integrated in some other action now?
Title: Re: New Playmaker Action: Get Forward
Post by: jeanfabre on February 08, 2017, 02:55:56 PM
Hi,

 it's a built in action :)
 
Bye,

 Jean