playMaker

Author Topic: New Playmaker Action: Get Character Controller Velocity  (Read 9476 times)

BilbyCoder

  • Playmaker Newbie
  • *
  • Posts: 8
New Playmaker Action: Get Character Controller Velocity
« on: April 01, 2011, 08:51:14 AM »
Alright boys, girls and small green things from alpha centuri...

I have just made my first custom action, to get the velocity of the character controller and store it in a Vector3.  I'm posting it here for 2 reasons.  First, because others may find it useful.  2, so that it can be checked and improved.

Licence... just use the damn thing, I copied most of the code from the other actions anyway.  ;D

Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Character)]
[Tooltip("Gets the velocity of the attached character controller")]
public class GetControllerVelocity : FsmStateAction
{
[RequiredField]
[CheckForComponent(typeof(CharacterController))]
public FsmOwnerDefault gameObject;
[RequiredField]
[UIHint(UIHint.Variable)]
public FsmVector3 storeResult;
public bool everyFrame;

GameObject previousGo;
CharacterController controller;

public override void Reset()
{
gameObject = null;
storeResult = null;
everyFrame = false;
}

public override void OnEnter()
{
doGetVelocity();
if (!everyFrame) Finish();
}

public override void OnUpdate()
{
doGetVelocity();
}

public void doGetVelocity()
{
GameObject go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go == null) return;

if (go != previousGo)
{
controller = go.GetComponent<CharacterController>();
previousGo = go;
}

if (controller != null)
{
storeResult.Value = controller.velocity;
}
}
}
}

I know that the documents say don't use the same namespace, but I couldn't get it to recognise FsmStateAction any other way.  If someone knows how to fix that, please tell me.  I'm still fairly new to namespaces.

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
Re: New Playmaker Action: Get Character Controller Velocity
« Reply #1 on: April 01, 2011, 07:56:41 PM »
To use the FsmStateAction class, add this to the top of your script.

Code: [Select]
#using HutongGames.PlayMaker;
That will bring in the required references for you.

BilbyCoder

  • Playmaker Newbie
  • *
  • Posts: 8
Re: New Playmaker Action: Get Character Controller Velocity
« Reply #2 on: April 01, 2011, 09:14:10 PM »
Indeed it would.

Thanks for that.

Kieren

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: New Playmaker Action: Get Character Controller Velocity
« Reply #3 on: May 10, 2011, 03:01:49 AM »
Uhm,

 Now I realized I used that namespace everytime when sharing custom actions.

 Alex, would you prefer me going over my scripts and change that to not use that namespace?

 Bye,

 Jean

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: New Playmaker Action: Get Character Controller Velocity
« Reply #4 on: May 10, 2011, 07:24:04 AM »
From what we've gathered, the only difference namespace makes is in organizing actions in its own block inside the Playmaker actions list. According to Sandro it also allows having different yet same-named actions/cs files in different "folders", but don't quote me on that 'coz I wouldn't trust Unity allowing that to happen.. 8)
--
Breno "MaDDoX" Azevedo
@brenoazevedo