playMaker

Author Topic: Get Rotation Speed  (Read 3934 times)

julius

  • Playmaker Newbie
  • *
  • Posts: 15
Get Rotation Speed
« on: January 24, 2013, 11:30:51 PM »
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.

Code: [Select]
// (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;
}


}
}
« Last Edit: January 24, 2013, 11:38:34 PM by julius »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Get Rotation Speed
« Reply #1 on: January 25, 2013, 01:59:48 AM »
Hi,

 no, you're good, it wasn't available before. thanks :)

bye,

 Jean