playMaker

Author Topic: New Playmaker Action: Get Forward  (Read 17776 times)

BilbyCoder

  • Playmaker Newbie
  • *
  • Posts: 8
New Playmaker Action: Get Forward
« 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;
}
}

}

BilbyCoder

  • Playmaker Newbie
  • *
  • Posts: 8
New Playmaker Action: Get Direction Vector (transform)
« Reply #1 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;
}
}

}

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: New Playmaker Action: Get Forward
« Reply #2 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?

BilbyCoder

  • Playmaker Newbie
  • *
  • Posts: 8
Re: New Playmaker Action: Get Forward
« Reply #3 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


tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: New Playmaker Action: Get Forward
« Reply #4 on: April 03, 2011, 04:31:46 AM »
Thanks Bilby!

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: New Playmaker Action: Get Forward
« Reply #5 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?
--
Breno "MaDDoX" Azevedo
@brenoazevedo

miketolsa

  • Playmaker Newbie
  • *
  • Posts: 22
  • Just love playmaker !!!
    • 4Buffs Productions
Re: New Playmaker Action: Get Forward
« Reply #6 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 .......

JeremyP

  • Playmaker Newbie
  • *
  • Posts: 1
Re: New Playmaker Action: Get Forward
« Reply #7 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.
« Last Edit: January 22, 2016, 09:35:55 AM by JeremyP »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: New Playmaker Action: Get Forward
« Reply #8 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

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: New Playmaker Action: Get Forward
« Reply #9 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?
Available for Playmaker work

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: New Playmaker Action: Get Forward
« Reply #10 on: February 08, 2017, 02:55:56 PM »
Hi,

 it's a built in action :)
 
Bye,

 Jean