playMaker

Author Topic: Jet Pack boost action  (Read 1494 times)

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Jet Pack boost action
« on: January 19, 2016, 05:33:29 AM »
This action gives you a jet pack boost effect you can turn on and off- I used the code from this tutorial to make the action https://www.youtube.com/watch?v=OIPpU7_RNVM

Here's the code- its also attached
Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Character)]
    [Tooltip("Boosts an object up for a jet pack like effect. Requires a character controller and a C# CharacterMotor script. ")]
    public class JetPack : FsmStateAction
    {
        [RequiredField]

        [CheckForComponent(typeof(CharacterMotor))]
        [CheckForComponent(typeof(CharacterController))]


        [Tooltip("The game object to boost")]
        public FsmOwnerDefault gameObject;

        [Tooltip("Amount of jetpack boost")]
        public FsmFloat fuel;

     
        public FsmBool everyFrame;

        CharacterMotor cm;
        CharacterController cc;

        public override void Reset()
        {
            gameObject = null;
            fuel = null;
            everyFrame = true;
           

        }

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

        }

        public override void OnUpdate()
        {
            if (everyFrame.Value)
            {
                DoJetPack();
            }
        }

        void DoJetPack()
        {
            var go = Fsm.GetOwnerDefaultTarget(gameObject);
            if (go == null)
            {
                return;
            }

            // Do jet pack boost. Boost amount is controlled by fuel

           
            cm = go.GetComponent<CharacterMotor>();
            cc = go.GetComponent<CharacterController>();

            Vector3 velocity = new Vector3(cc.velocity.x, fuel.Value, cc.velocity.z);
            cm.SetVelocity(velocity);


        }

    }
}

The action requires a CharacterController and a CharacterMotor C# script on the object for it to work. I attached a version of the CharacterMotor C# script as well in case you need one.
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!