Its an exact copy of Get Speed but it gets the "rigidbody.angularVelocity.magnitude" instead of the "rigidbody.velocity.magnitude".
Useful if you need to set a cap on the rotation speed of a rigidbody. If this functionality already exists in playmaker let me know and I'll remove the post.
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Gets the Rotational Speed of a Game Object and stores it in a Float Variable. NOTE: The Game Object must have a rigid body.")]
public class GetRotationSpeed : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Rigidbody))]
public FsmOwnerDefault gameObject;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmFloat storeResult;
public bool everyFrame;
public override void Reset()
{
gameObject = null;
storeResult = null;
everyFrame = false;
}
public override void OnEnter()
{
DoGetSpeed();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoGetSpeed();
}
void DoGetSpeed()
{
if (storeResult == null)
return;
GameObject go = gameObject.OwnerOption == OwnerDefaultOption.UseOwner ? Owner : gameObject.GameObject.Value;
if (go == null) return;
if (go.rigidbody == null) return;
Vector3 velocity = go.rigidbody.angularVelocity;
storeResult.Value = velocity.magnitude;
}
}
}