Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: Jake on December 11, 2012, 06:14:55 AM
-
Hi there,
first I'd like to say that I'm a new playMaker user and the more I see, the more I love it. Also I've planned to add playMaker support to my products (mainly Magical Box and Measure It! Pro) in the near future.
Here are some actions I've missed covering Unity's Random class:
RandomVector2:
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Creates a random Vector2 inside a unit circle")]
public class RandomVector2 : FsmStateAction
{
[UIHint(UIHint.Variable)]
public FsmVector2 storeResult;
public override void Reset()
{
storeResult = null;
}
public override void OnEnter()
{
storeResult.Value = Random.insideUnitCircle;
Finish();
}
}
}
RandomVector3:
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Creates a random Vector3 inside a unit sphere")]
public class RandomVector3 : FsmStateAction
{
[UIHint(UIHint.Variable)]
public FsmVector3 storeResult;
public override void Reset()
{
storeResult = null;
}
public override void OnEnter()
{
storeResult.Value = Random.insideUnitSphere;
Finish();
}
}
}
More to come...
Cheers
Jake
-
Why not use a random float and put that in vector 2 or 3?
-
Hm,
maybe I've missed something, but how do you create a random Vector3 by putting a random Float in it? Say you want to position a gameobject somewhere inside a sphere...
Jake
-
Hm,
maybe I've missed something, but how do you create a random Vector3 by putting a random Float in it? Say you want to position a gameobject somewhere inside a sphere...
Jake
If you know the x.y.z on that sphere you can take those values and use random float from them and use those x.y.z on the gameobject.
-
Ok, but that looks more like a workaround than a good solution to me. Nevertheless, it was easy to create those actions and I've found them possible useful for others, so I've shared them.
Jake
-
Added variable input for UnitSphere's radius, here it be!
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Math)]
[Tooltip("Creates a random Vector3 inside a unit sphere")]
public class RandomVector3 : FsmStateAction
{
[UIHint(UIHint.Variable)]
public FsmVector3 storeResult;
[Tooltip("Radius of imaginary sphere")]
public FsmFloat unitSphere;
public override void Reset()
{
storeResult = null;
unitSphere = null;
}
public override void OnEnter()
{
storeResult.Value = Random.insideUnitSphere*unitSphere.Value;
Finish();
}
}
}
-
Thanks for sharing! Its real time saver instead of breaking things up in random floats!
-
Thanks, but am I wrong, or is the UnitSphere always positioned at the center of the world? Shouldn't it be created relative to the Object that spawns it?
-
Hi,
you have a good point, but that would be an option, because it's very often the case that you want to have a random unit vector without caring of the actual gameobject, this is the case for all "managers" and logic features that must be attached to a GameObject because Unity made it so, which is beyond me to be honest... I don't see the point of having a transform on a GameObject that's not needed in the 3d world to begin with.
I also realized that them actions are not on the ecosystem, I'll add them next week with this option of being relative to a gameobject.
Bye,
Jean
-
I believe these were never added to the ecosystem?
-
Hi,
Thanks for the reminder :)
I added several features
-- ability to set the seed for predictable results ( leave to none for general purpose)
-- everyFrame Option
-- option to get the random values inside the radius or on the perimeter/surface.
You can search and download them on the Ecosystem
sources:
RandomVector2 (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/Assets/PlayMaker%20Custom%20Actions/Vector2/RandomVector2.cs)
RandomVector3 (https://github.com/jeanfabre/PlayMakerCustomActions_U3/blob/master/Assets/PlayMaker%20Custom%20Actions/Vector3/RandomVector3.cs)
Bye,
Jean
-
just found these, super useful :D
question! Could the randomvector2 action get a gameobject/position variable input for Center as well as axis? :D
-
Hi,
I don't understand your question. I guess a vector can both represent a center to position an object, OR a direction, it's up to you and doesn't change the principle of a vector.
however, for a direction, you could normalize the random vector, so that the magnitude of the vector is 1, which is prefferable for a vector that expresses a direction. Does that make sense?
Bye,
Jean