playMaker

Author Topic: Vector3 ProjectOnPlane  (Read 2971 times)

pez

  • Playmaker Newbie
  • *
  • Posts: 12
Vector3 ProjectOnPlane
« 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

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

Thanks
« Last Edit: August 21, 2018, 11:17:41 PM by pez »

virgin

  • Playmaker Newbie
  • *
  • Posts: 1
Re: Vector3 ProjectOnPlane
« Reply #1 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!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Vector3 ProjectOnPlane
« Reply #2 on: October 18, 2018, 04:25:35 AM »
Hi,

 nice! I added it to the Ecosystem :)

 Bye,

 Jean

pez

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Vector3 ProjectOnPlane
« Reply #3 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