Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: jimbobulus on October 26, 2012, 04:25:29 PM
-
Hi, I noticed there was no get/set for a rigidbody when I needed it, so I copied and pasted the get/set velocity code to get the angular velocity instead.
So barely any work by me at all! But I hope you guys find them as useful as I did! :)
GetAngularVelocity
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Gets the Angular Velocity of a Game Object and stores it in a Vector3 Variable or each Axis in a Float Variable. NOTE: The Game Object must have a Rigid Body.")]
public class GetAngularVelocity : FsmStateAction {
[RequiredField]
[CheckForComponent(typeof(Rigidbody))]
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 Space space;
public bool everyFrame;
public override void Reset()
{
gameObject = null;
vector = null;
x = null;
y = null;
z = null;
space = Space.World;
everyFrame = false;
}
public override void OnEnter()
{
DoGetAngularVelocity();
if (!everyFrame)
Finish();
}
public override void OnUpdate()
{
DoGetAngularVelocity();
}
void DoGetAngularVelocity()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;
if (go.rigidbody == null) return;
Vector3 angularVelocity = go.rigidbody.angularVelocity;
if (space == Space.Self)
angularVelocity = go.transform.InverseTransformDirection(angularVelocity);
vector.Value = angularVelocity;
x.Value = angularVelocity.x;
y.Value = angularVelocity.y;
z.Value = angularVelocity.z;
}
}
}
SetAngularVelocity
using UnityEngine;
namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Sets the Angular Velocity of a Game Object. To leave any axis unchanged, set variable to 'None'. NOTE: Game object must have a rigidbody.")]
public class SetAngularVelocity : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(Rigidbody))]
public FsmOwnerDefault gameObject;
[UIHint(UIHint.Variable)]
public FsmVector3 vector;
public FsmFloat x;
public FsmFloat y;
public FsmFloat z;
public Space space;
public bool everyFrame;
public override void Reset()
{
gameObject = null;
vector = null;
// default axis to variable dropdown with None selected.
x = new FsmFloat { UseVariable = true };
y = new FsmFloat { UseVariable = true };
z = new FsmFloat { UseVariable = true };
space = Space.Self;
everyFrame = false;
}
public override void OnEnter()
{
DoSetAngularVelocity();
if (!everyFrame)
{
Finish();
}
}
public override void OnFixedUpdate()
{
DoSetAngularVelocity();
if (!everyFrame)
Finish();
}
void DoSetAngularVelocity()
{
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null || go.rigidbody == null)
{
return;
}
// init position
Vector3 angularVelocity;
if (vector.IsNone)
{
angularVelocity = space == Space.World ?
go.rigidbody.angularVelocity :
go.transform.InverseTransformDirection(go.rigidbody.angularVelocity);
}
else
{
angularVelocity = vector.Value;
}
// override any axis
if (!x.IsNone) angularVelocity.x = x.Value;
if (!y.IsNone) angularVelocity.y = y.Value;
if (!z.IsNone) angularVelocity.z = z.Value;
// apply
go.rigidbody.angularVelocity = space == Space.World ? angularVelocity : go.transform.TransformDirection(angularVelocity);
}
}
}
-
A belated thanks for these! I came here looking for exactly this.
-
i didn't mean to dig this topic up again. But I just want to say "Thank you" :) i'm looking for this action :)
-
Hi, thanks for these adaptations.
These actions don't seem to work with the new Rigidbody 2d.
I add torque2d to an object with a rigidbody2d, but when I use GetAngularVelocity I get 0 on all three axis, both on world and local space.
Is it possible to adapt the actions to the new 2d system?
-
I'm using the 2D system and want to have an object's Z rotation change from 0 to -90 degrees based on it's downward velocity (example: nose of plane dips towards ground faster it falls). I have a working script, but wanted to know how to translate this to Playmaker. Not sure which Actions / Variables I need in PM. I see no Euler options, etc.
float maxSpeed = 3f;
velocity = Vector3 (velocity, maxSpeed);
transform.position += velocity * Time.deltaTime;
float angle = 0;
if (velocity.y < 0) {
angle = Mathf.Lerp(0, -90, -velocity.y);
}
transform.rotation = Quaternion.Euler(0, 0, angle);
-
Hi,
I created a whole set of Custom Actions to work with Quaternions, then you can do that euler to quaternion procedure.
https://hutonggames.fogbugz.com/default.asp?W967
bye,
Jean
-
Pretty essential if you're moving around/pooling rigid bodies so thanks for this
-
Sorry to drag up such an old thread, but I really need these scripts... but Unity says they are obsolete. Any chance of an updated version?
-
For more detail on the problem, this is what Visual Studio throws up. Any help would be awesome, really surprised this isn't a standard function of Playmaker.
Error CS0619 'GameObject.rigidbody' is obsolete: 'Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\GetAngularVelocity.cs 52 Active
Error CS0619 'GameObject.rigidbody' is obsolete: 'Property rigidbody has been deprecated. Use GetComponent<Rigidbody>() instead. (UnityUpgradable)' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\GetAngularVelocity.cs 54 Active
Error CS1061 'Component' does not contain a definition for 'angularVelocity' and no extension method 'angularVelocity' accepting a first argument of type 'Component' could be found (are you missing a using directive or an assembly reference?) Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\GetAngularVelocity.cs 54 Active
Warning CS0108 'AudioMute.audio' hides inherited member 'Component.audio'. Use the new keyword if hiding was intended. Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\AudioMute.cs 7 Active
Warning CS0108 'SplashController.animation' hides inherited member 'Component.animation'. Use the new keyword if hiding was intended. Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Tales From The Rift\Splash\SplashController.cs 10 Active
Warning CS0618 'Renderer.castShadows' is obsolete: 'Property castShadows has been deprecated. Use shadowCastingMode instead.' Go For Launch Pre Alpha 0.1.CSharp.Plugins C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Plugins\PuffySmoke\Scripts\Puffy_Renderer.cs 1815 Active
Warning CS0618 'Material.Material(string)' is obsolete: 'Creating materials from shader source string will be removed in the future. Use Shader assets instead.' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\CameraPath3\Scripts\Util\CameraDeAlpha.cs 11 Active
Warning CS0618 'Application.LoadLevel(string)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\CircularGravityForce Package\Scrips\Misc\SceneSettings.cs 112 Active
Warning CS0618 'Application.loadedLevelName' is obsolete: 'Use SceneManager to determine what scenes have been loaded' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\CircularGravityForce Package\Scrips\Misc\SceneSettings.cs 112 Active
Warning CS0618 'Application.LoadLevel(string)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\CircularGravityForce Package\Scrips\Misc\SceneSettings.cs 194 Active
Warning CS0618 'Application.LoadLevel(int)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\PuffySmoke sample scenes\Scripts\Others\GuiControls.cs 50 Active
Warning CS0618 'Application.loadedLevel' is obsolete: 'Use SceneManager to determine what scenes have been loaded' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\PuffySmoke sample scenes\Scripts\Others\GuiControls.cs 50 Active
Warning CS0618 'Application.levelCount' is obsolete: 'Use SceneManager.sceneCountInBuildSettings' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\PuffySmoke sample scenes\Scripts\Others\GuiControls.cs 50 Active
Warning CS0618 'Application.LoadLevel(int)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Screen Fader Pack\Code\Fader.cs 1096 Active
Warning CS0618 'Application.LoadLevel(string)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Screen Fader Pack\Code\Fader.cs 1098 Active
Warning CS0618 'Application.loadedLevel' is obsolete: 'Use SceneManager to determine what scenes have been loaded' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Screen Fader Pack\Demo\Demo - Object Fading\DemoObjectFadingGUI.cs 198 Active
Warning CS0618 'TextEditor.content' is obsolete: 'Please use 'text' instead of 'content'' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Screen Fader Pack\Demo\Demo - Object Fading\DemoObjectFadingGUI.cs 469 Active
Warning CS0618 'TextEditor.content' is obsolete: 'Please use 'text' instead of 'content'' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Screen Fader Pack\Demo\Demo - Object Fading\DemoObjectFadingGUI.cs 477 Active
Warning CS0618 'TextEditor.content' is obsolete: 'Please use 'text' instead of 'content'' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Screen Fader Pack\Demo\Demo - Object Fading\DemoObjectFadingGUI.cs 480 Active
Warning CS0618 'Screen.lockCursor' is obsolete: 'Property lockCursor has been deprecated. Use Cursor.lockState and Cursor.visible instead.' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\CustomPointer.cs 48 Active
Warning CS0618 'Screen.lockCursor' is obsolete: 'Property lockCursor has been deprecated. Use Cursor.lockState and Cursor.visible instead.' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\DemoUI.cs 27 Active
Warning CS0618 'Screen.lockCursor' is obsolete: 'Property lockCursor has been deprecated. Use Cursor.lockState and Cursor.visible instead.' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\DemoUI.cs 29 Active
Warning CS0618 'Application.loadedLevel' is obsolete: 'Use SceneManager to determine what scenes have been loaded' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\DemoUI.cs 45 Active
Warning CS0618 'Application.LoadLevel(int)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\DemoUI.cs 63 Active
Warning CS0618 'Application.LoadLevel(int)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\DemoUI.cs 66 Active
Warning CS0618 'Application.LoadLevel(int)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\DemoUI.cs 69 Active
Warning CS0618 'Application.LoadLevel(int)' is obsolete: 'Use SceneManager.LoadScene' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\DemoUI.cs 72 Active
Warning CS0618 'Application.loadedLevel' is obsolete: 'Use SceneManager to determine what scenes have been loaded' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Spaceflight Controls\Scripts\DemoUI.cs 81 Active
Warning CS0618 'Application.LoadLevelAsync(string)' is obsolete: 'Use SceneManager.LoadSceneAsync' Go For Launch Pre Alpha 0.1.CSharp C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\Tales From The Rift\Splash\SplashController.cs 26 Active
Warning CS0618 'EditorApplication.currentScene' is obsolete: 'Use EditorSceneManager to see which scenes are currently loaded' Go For Launch Pre Alpha 0.1.CSharp.Editor C:\Users\Joe\Documents\Go For Launch Pre Alpha 0.1\Assets\CameraPath3\Editor\CameraPathEditorInspectorGUI.cs 1738 Active
-
Hi,
Please run the Unity Api updater, it will fix this.
I have this thread as a pending todo for some weeks now... Time to make it happen... I'll clean it up and put it on the ecosystem asap.
Bye,
Jean
-
Hi,
ok, they are both up on the Ecosystem now, let me know how it goes on your end.
Bye,
Jean
-
Great thanks! All working as it should