playMaker

Author Topic: CharacterMotor and PlatformController Script Actions  (Read 13809 times)

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
CharacterMotor and PlatformController Script Actions
« on: June 11, 2011, 12:40:58 AM »
I am in over my head with the amount of information I've been absorbing lately, to such a point that I only discovered this forum, which I have been wishing for for months, today.  Well!  Time to share some actions!

Here is an action that exposes all the variables within the CharacterMotor script:

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;

[ActionCategory(ActionCategory.Character)]
[Tooltip("Interface to CharacterMotor component")]
public class CharacterMotorAction : FsmStateAction {
    [RequiredField]
[CheckForComponent(typeof(CharacterMotor))]
public FsmOwnerDefault owner;

CharacterMotor motor;
GameObject previousGameObject;

public FsmBool CanControl = true;
public FsmFloat ForwardSpeed = 10f;
public FsmFloat SidewaysSpeed = 10f;
public FsmFloat BackwardsSpeed = 10f;
public FsmFloat MaxGroundAcceleration = 30f;
public FsmFloat MaxAirAcceleration = 20f;
public FsmFloat Gravity = 10f;
public FsmFloat MaxFallSpeed = 20f;
public FsmBool JumpingEnabled = true;
public FsmFloat BaseHeight = 1f;
public FsmFloat ExtraHeight = 4.1f;

public override void Reset()
{
owner = null;
}

public override void OnEnter ()
{
GameObject gameObject = Fsm.GetOwnerDefaultTarget(owner);
if (gameObject == null)
return;

if (gameObject != previousGameObject) {
motor = gameObject.GetComponent<CharacterMotor>();
previousGameObject = gameObject;
}

if (motor == null)
return;

CharacterMotorMovement movement = motor.movement;
CharacterMotorJumping jumping = motor.jumping;

motor.canControl = CanControl.Value;
movement.maxForwardSpeed = ForwardSpeed.Value;
movement.maxSidewaysSpeed = SidewaysSpeed.Value;
movement.maxBackwardsSpeed = BackwardsSpeed.Value;
movement.maxGroundAcceleration = MaxGroundAcceleration.Value;
movement.maxAirAcceleration = MaxAirAcceleration.Value;
movement.gravity = Gravity.Value;
movement.maxFallSpeed = MaxFallSpeed.Value;
jumping.enabled = JumpingEnabled.Value;
jumping.baseHeight = BaseHeight.Value;
jumping.extraHeight = ExtraHeight.Value;
}
}

Just look at it.  It's so beautiful.

Here is another action which exposes the variables within the Platform Input Controller:

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;

[ActionCategory(ActionCategory.Character)]
[Tooltip("Interface to PlatformInputController component")]
public class PlatformInputControllerAction : FsmStateAction {
    [RequiredField]
[CheckForComponent(typeof(PlatformInputController))]
public FsmOwnerDefault owner;

PlatformInputController controller;
GameObject previousGameObject;

public FsmBool AutoRotate = true;
public FsmFloat MaxRotationSpeed = 360f;

public override void Reset()
{
owner = null;
}

public override void OnEnter ()
{
GameObject gameObject = Fsm.GetOwnerDefaultTarget(owner);
if (gameObject == null)
return;

if (gameObject != previousGameObject) {
controller = gameObject.GetComponent<PlatformInputController>();
previousGameObject = gameObject;
}

if (controller == null)
return;

controller.autoRotate = AutoRotate.Value;
controller.maxRotationSpeed = MaxRotationSpeed.Value;
}
}

They're like a cute couple, aren't they?  They go well together, which is why I had my swell friend Martijn Zandvliet write them up for me.  (I'm a pathetic scripter, but I blame PlayMaker for it).

I hope these are as useful for you all as they have been for me.  Cheers!  :)
« Last Edit: March 23, 2012, 08:14:32 AM by jeanfabre »

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: CharacterMotor and PlatformController Script Actions
« Reply #1 on: June 11, 2011, 01:13:39 AM »
Thanks for sharing!

mrbdrm

  • Playmaker Newbie
  • *
  • Posts: 39
Re: CharacterMotor and PlatformController Script Actions
« Reply #2 on: June 11, 2011, 03:17:48 AM »
hi , thanks for sharing
however im having problem importing them , see the screen shot .

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: CharacterMotor and PlatformController Script Actions
« Reply #3 on: June 11, 2011, 04:29:09 AM »
Do you have CharacterMotor and PlatformController installed? They need to be installed before you can use these actions.

mrbdrm

  • Playmaker Newbie
  • *
  • Posts: 39
Re: CharacterMotor and PlatformController Script Actions
« Reply #4 on: June 11, 2011, 05:02:28 AM »
i have them on my main char

artician

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 318
Re: CharacterMotor and PlatformController Script Actions
« Reply #5 on: June 13, 2011, 05:30:22 PM »
@mrbdrm: did you ever solve your problem?  I'm afraid I can't offer much help.  I can say that the addition of a script or other component in my project has forced me to reimport Playmaker several times in the past, which was the only solution that I could find to similar issues.  It doesn't appear that the obstacle you're having a problem with is PlayMaker though.  I hope you figured it out!

Kid

  • Playmaker Newbie
  • *
  • Posts: 6
Re: CharacterMotor and PlatformController Script Actions
« Reply #6 on: December 04, 2011, 12:18:51 PM »
Artician, thank you for sharing. Indeed it's very useful.

bigzer

  • Playmaker Newbie
  • *
  • Posts: 11
  • 1.3
Re: CharacterMotor and PlatformController Script Actions
« Reply #7 on: March 23, 2012, 06:38:35 AM »
Thanks for sharing looks very usefull.

I have an error during the import though;

Assets/PlayMaker/Actions/PlatformInputControllerAction.cs(12,9): error CS0246: The type or namespace name `PlatformInputController' could not be found. Are you missing a using directive or an assembly reference?

same with the motor:

Assets/PlayMaker/Actions/CharacterMotorAction.cs(12,9): error CS0246: The type or namespace name `CharacterMotor' could not be found. Are you missing a using directive or an assembly reference?

I have both CharacterMotor.js and PlatformInputController.js in my project. My character has both controller and motor attached.

Any idea what it could be?

bigzer

  • Playmaker Newbie
  • *
  • Posts: 11
  • 1.3
Re: CharacterMotor and PlatformController Script Actions
« Reply #8 on: March 23, 2012, 07:11:38 AM »
I found the solution:

CharacterMotor.js and PlatformInputController.js have to be placed in /Standard Assets/ folder of your project

Thanks for the action ^^
regards

amaranth

  • Full Member
  • ***
  • Posts: 172
Re: CharacterMotor and PlatformController Script Actions
« Reply #9 on: April 11, 2012, 10:48:08 PM »
This is just what I needed. Thank you!

Vanlande

  • Playmaker Newbie
  • *
  • Posts: 5
Re: CharacterMotor and PlatformController Script Actions
« Reply #10 on: April 14, 2012, 01:32:29 PM »
Great scripts! Just a heads up for all who are using these scripts. Noticed that when you added these actions to an event, such event never FINISHED. At first I thought they were supposed to mimic an always update event, but later noticed that was not the case. So I took a second peek at the code (you can see it for yourself), the code only runs once, since its in OnEnter function, but it never calls Finish(), so it just hangs there forever and never really does anything else, nor it updates every frame.
Thought you should know, in case anyone wanted to change it. I myself thought PlayMaker was acting funny but it seems it was just an oversight  :D
« Last Edit: April 14, 2012, 01:40:28 PM by Vanlande »

tbelgrave

  • Playmaker Newbie
  • *
  • Posts: 42
    • Ispyr Inc
Re: CharacterMotor and PlatformController Script Actions
« Reply #11 on: October 13, 2012, 01:39:40 PM »
Hi, I'm  trying to implement these scripts and I've received a series of messages similar to mrbdrm

Quote
Assets/PlayMaker/Actions/CharacterMotorAction.cs(50,26): error CS1061: Type `CharacterMotorMovement' does not contain a definition for `maxForwardSpeed' and no extension method `maxForwardSpeed' of type `CharacterMotorMovement' could be found (are you missing a using directive or an assembly reference?)

and it repeats for maxForwardSpeed, maxSidewaysSpeed e.t.c. I even tried bigzer suggestion and still no joy, I would love to get this working as I'm following justifun's example here  http://hutonggames.com/playmakerforum/index.php?topic=1171.0

thx
« Last Edit: October 13, 2012, 01:41:15 PM by lildragn »

tbelgrave

  • Playmaker Newbie
  • *
  • Posts: 42
    • Ispyr Inc
Re: CharacterMotor and PlatformController Script Actions
« Reply #12 on: October 14, 2012, 02:25:52 PM »
Awesome, got it to work this morning. I imported the charactermotor action only without the input..cs and it came in without error. Not sure what it was.

gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: CharacterMotor and PlatformController Script Actions
« Reply #13 on: January 12, 2013, 02:23:06 PM »
tried every single folder,still wont install inside the project,where is the project standard assets folder for mac

gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: CharacterMotor and PlatformController Script Actions
« Reply #14 on: January 12, 2013, 03:14:54 PM »
found it final because it was named character controller i didn't realise it was it,another question what do you use to get the character off the floor to jump,ive seen add force but you need a rigidbody for that.