Playmaker Forum

PlayMaker Feedback => Action Requests => Topic started by: pez on August 21, 2018, 11:11:42 PM

Title: Vector3 ProjectOnPlane
Post by: pez on August 21, 2018, 11:11:42 PM
Hi,

I'm trying to make my character controller work with spherical gravity (mario galaxy style) & am getting some tips along the way by a coder friend on the calculations I need to do.

I'm stuck at trying to keep him upright on the planet though, as part of it requires this vector3 method - https://docs.unity3d.com/2017.1/Documentation/ScriptReference/Vector3.ProjectOnPlane.html (https://docs.unity3d.com/2017.1/Documentation/ScriptReference/Vector3.ProjectOnPlane.html)

Anyone able to create an action that does this for me? It would be greatly appreciated!

Thanks
Title: Re: Vector3 ProjectOnPlane
Post by: virgin on October 15, 2018, 11:04:40 AM
Hi,
You can try using attached code for the action to perform:
Code: [Select]
using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
   [ActionCategory(ActionCategory.Vector3)]
   [Tooltip("Performs projection of a vector on a plane using its normal.")]
   public class Vector3ProjectOnPlane : FsmStateAction
   {
      [RequiredField]
      public FsmVector3 vector;
      [RequiredField]
      public FsmVector3 planeNormal;

      [UIHint(UIHint.Variable)]
      public FsmVector3 storeVector3Result;

      public bool everyFrame;

      public override void Reset()
      {
         vector = null;
         planeNormal = null;
         storeVector3Result = null;
         everyFrame = false;
      }

      public override void OnEnter()
      {
         DoProjectOnPlane();

         if (!everyFrame)
         {
            Finish();
         }
      }

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

      void DoProjectOnPlane()
      {
            storeVector3Result.Value = Vector3.ProjectOnPlane(vector.Value, planeNormal.Value);
      }
   }
}
Cheers!
Title: Re: Vector3 ProjectOnPlane
Post by: jeanfabre on October 18, 2018, 04:25:35 AM
Hi,

 nice! I added it to the Ecosystem :)

 Bye,

 Jean
Title: Re: Vector3 ProjectOnPlane
Post by: pez on November 20, 2018, 10:04:43 PM
Hi,

Just noticed this in the ecosystem whilst browsing for something else. Thanks for adding it!
I ended up doing a work around with some other functions, but will definitely make use of this when the time comes again.

Thanks