Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started 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.
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;
}
}
}
-
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.
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;
}
}
}
-
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?
-
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
-
Thanks Bilby!
-
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?
-
is it possible to make this action work .........
As I want the forward direction to make or add force to that direction .......
-
It does work, as is, though you need to make some namespace/tooltip changes at the top of the code if I remember correctly.
-
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
-
Hi, i can't find this action in the Ecosystem, is it integrated in some other action now?
-
Hi,
it's a built in action :)
Bye,
Jean