playMaker

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Digitom

Pages: [1] 2 3 4
1
sure thing

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2020. All rights reserved.
//Original action: https://hutonggames.com/playmakerforum/index.php?topic=21655.msg95032#msg95032
/*--- __ECO__ __PLAYMAKER__ __ACTION__ ---*/

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
    [ActionCategory(ActionCategory.Transform)]
    [Tooltip("Gets the world transform velocity and direction of a GameObject")]
    public class GetTransformVelocity : FsmStateAction
    {
        public enum UpdateType { Update, FixedUpdate, LateUpdate}

        [RequiredField]
        [UIHint(UIHint.Variable)]
        public FsmOwnerDefault gameObject;

        [Tooltip("Store the direction / velocity")]
        [UIHint(UIHint.Variable)]
        public FsmVector3 storeDirection;

        [Tooltip("Store local direction or world?")]
        public Space space;

        [Tooltip("Store the magnitude / speed")]
        [UIHint(UIHint.Variable)]
        public FsmFloat storeMagnitude;
       
        [Tooltip("Store the square magnitude / speed. Takes less performances")]
        [UIHint(UIHint.Variable)]
        public FsmFloat storeSquareMagnitude;
       
        public UpdateType updateType;
       
        private Vector3 _lastPos;
        private Vector3 _direction;
        private GameObject _go;

        public override void Reset()
        {
            gameObject = null;
            storeDirection = null;
            storeMagnitude = null;
            storeSquareMagnitude = null;
        }

        public override void OnPreprocess()
        {
            if (updateType == UpdateType.FixedUpdate)
                Fsm.HandleFixedUpdate = true;
            else if (updateType == UpdateType.LateUpdate)
                Fsm.HandleLateUpdate = true;
        }

        public override void OnEnter()
        {
            _go = Fsm.GetOwnerDefaultTarget(gameObject);
            _lastPos = _go.transform.position;
        }

        public override void OnUpdate()
        {
            if (updateType == UpdateType.Update)
                CalculateSpeed();
        }

        public override void OnFixedUpdate()
        {
            if (updateType == UpdateType.FixedUpdate)
                CalculateSpeed();
        }

        public override void OnLateUpdate()
        {
            if (updateType == UpdateType.LateUpdate)
                CalculateSpeed();
        }

        void CalculateSpeed()
        {
           
            _direction = _go.transform.position - _lastPos;
           
            if (!storeSquareMagnitude.IsNone) storeSquareMagnitude.Value = Mathf.Round((_direction / Time.deltaTime).sqrMagnitude * 100f) / 100f;

            if (!storeMagnitude.IsNone) storeMagnitude.Value = Mathf.Round((_direction / Time.deltaTime).magnitude * 100f) / 100f;

            _direction = _direction.normalized;
           
            if (space == Space.Self) _direction = _go.transform.InverseTransformDirection(_direction);
           
            if (!storeDirection.IsNone) storeDirection.Value = _direction;
           
            _lastPos = _go.transform.position;
        }

    }
}

2
Hello Jean,

Apologies but I had to fix this again. Had to add the initial position in the OnEnter.

Please update on the ecosystem, Thanks!

3
Share New Actions / Unity Input System [In Preview] Actions
« on: March 11, 2020, 02:59:49 PM »
Hello,

I am not sure if there are any input actions here yet so I decided to make some simple ones. I know Thore was looking into this in another thread.

These work as long as you set up your input action asset file.

I may be adding to this an improving and will update here


4
Feature Requests / Stackable / Duplicate Custom Editor Attributes
« on: March 11, 2020, 12:52:30 PM »
In the normal unity editor you are permitted to stack custom editor attributes so it applies to multiple editor scripts.

Any way we can do this? Would save TONS of time when making custom editors. Or maybe I am missing something? Do I HAVE to make a custom editor for every script that inherits a fancy base class function?

Code: [Select]
namespace HutongGames.PlayMakerEditor
{
    [CustomActionEditor(typeof(InputSystemReadVector2Value))]
    [CustomActionEditor(typeof(InputSystemReadBoolValue))]
    [CustomActionEditor(typeof(InputSystemTriggeredValue))]
    public class InputSystemTriggeredValueEditor : InputSystemBaseEditor
    {
        public override bool OnGUI()
        {
            base.OnGUI();
            EditField("storeValue");

            return GUI.changed;
        }
    }
}

Thanks

5
Tbh this action is quite useless/inefficient to someone who knows how to code custom actions...but may help some FSMs in dealing with objects currently updating in fixed or late update (like controllers or cameras).

I personally have had to use this for calculating velocity movement of a transform that was moving in fixed update. When I used the normal next frame event action to loop back to the calculations, my results were not consistent. I ended up making a fixed update next frame action and it was solid...but ended up making a custom action for velocity movement anyways. Might help some people though so thought ide share.

6
Hello,

Quickly made this action per request.



Cheers,

7
This action would be absolutely boss (wink wink) if it were a hybrid of the original Send Event action, all with its sending modes glory, and the frame type plus the frame based delay functions.

attached ;)

8
this look awesome... I'll be away from my computer for a few days, so can't test it right now, but will this be able to work in a pool game? Like detect where the white ball will go? and also would it work with ramps (i was thinking of golf games) ?

Any way looks super!!

It won't detect deflections/bounces atm...or resistance of surfaces...I mayyyy add that but it introduces more room for error.

9
Hello,

I made a custom action to predict rigidbody projectiles into a Vector3 FSMArray.
Also made a custom action to set line renderer points based on a vector3 FSMArray.

Useful for angry bird type games or previewing grenade throws and stuff like that. Feel free to add this to the ecosystem!



10
Hi Jean,

I was using this to do a very specific loop where I needed to predict velocity of a transform. When I used next frame the values would spaz out but were solid when I made this fixed next frame action.

I ended up just making that GetTransformVelocity action eventually though.

11
Hello,

I updated the Next Frame Advance(d?) script so it has the option for fixed or late updates. Useful if you need these options for physics-based objects or fixed movement.




12
Share New Actions / Axis Value Event
« on: February 06, 2020, 11:05:38 AM »
Hello,

Made an action that sends an event based on the value of an axis input. Useful if you are using triggers on controllers as "buttons".


13
Thanks Jean,

I will cache variables in the future from now on when doing this stuff and follow this other formatting.

Just a heads up you may need to round the sqr magnitude as well or you get some wonky values popping up.

Code: [Select]
void CalculateSpeed()
        {
            _go = Fsm.GetOwnerDefaultTarget(gameObject);
           
            _direction = _go.transform.position - lastPos;
           
            if (!storeSquareMagnitude.IsNone) storeSquareMagnitude.Value = Mathf.Round((_direction / Time.deltaTime).sqrMagnitude * 100f) / 100f;

            if (!storeMagnitude.IsNone) storeMagnitude.Value = Mathf.Round((_direction / Time.deltaTime).magnitude * 100f) / 100f;

            _direction = _direction.normalized;
           
            if (space == Space.Self) _direction = _go.transform.InverseTransformDirection(_direction);
           
            if (!storeDirection.IsNone) storeDirection.Value = _direction;
           
            lastPos = _go.transform.position;
        }

14
Share New Actions / Get Transform Velocity / Direction , Speed / Magnitude
« on: February 05, 2020, 11:44:39 AM »
Hello,

I created an action that gets the actual velocity of the gameobject's Transform. This is useful for syncing animations that depend on the actual movement of a object versus syncing animations through inputs. Also useful if you move your player through a transform and not the rigidbody. Also threw in a getter for speed / magnitude as well.


15
Share New Actions / Has FSM Template / Has FSM Name (Free)
« on: January 16, 2020, 08:08:22 AM »
Hello,

I whipped up these actions today because I needed to check if my objects contained a certain fsm.

Feel free to add them to the ecosystem as well!


Pages: [1] 2 3 4