Physics tasks for adding torque and other physics forces

NodeCanvas Forums Custom Nodes & Tasks Physics tasks for adding torque and other physics forces

This topic contains 3 replies, has 3 voices, and was last updated by  AVOlight 1 week, 2 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #13613

    AVOlight
    Participant

    Are these available somewhere?

    #13620

    sinzer0
    Participant

    I created a couple of custom ones awhile ago. Not sure if there is alternatives or better but here you go

    
    using NodeCanvas.Framework;
    using ParadoxNotion.Services;
    using ParadoxNotion.Design;
    using UnityEngine;
    
    [Category("Physics")]
        [Description("Add a force to a rigidbody in fixed update.")]
        public class AddForce : ActionTask<Rigidbody>
        {
            public BBParameter<Vector3> forceVector;
            public BBParameter<ForceMode> mode;
            public BBParameter<bool> relative = true;
    
            protected override void OnExecute()
            {
                MonoManager.current.onFixedUpdate += OnFixedUpdate;
            }
    
            void OnFixedUpdate()
            {
                if(relative.value)
                {
                    agent.AddRelativeForce(forceVector.value, mode.value);
                }
                else
                {
                    agent.AddForce(forceVector.value, mode.value);
                }
                    
            }
    
            protected override void OnStop()
            {
                MonoManager.current.onFixedUpdate -= OnFixedUpdate;
            }
        }
    
    
    using NodeCanvas.Framework;
    using ParadoxNotion.Services;
    using ParadoxNotion.Design;
    using UnityEngine;
    
     [Category("Physics")]
        [Description("Add torque to a rigidbody in fixed update.")]
        public class AddTorque : ActionTask<Rigidbody>
        {
            public BBParameter<Vector3> torqueVector;
            public BBParameter<ForceMode> mode;
            public BBParameter<bool> relative = true;
    
            protected override void OnExecute()
            {
                MonoManager.current.onFixedUpdate += OnFixedUpdate;
            }
    
            void OnFixedUpdate()
            {
                if (relative.value)
                {
                    agent.AddRelativeTorque(torqueVector.value, mode.value);
                }
                else
                {
                    agent.AddTorque(torqueVector.value, mode.value);
                }
    
            }
    
            protected override void OnStop()
            {
                MonoManager.current.onFixedUpdate -= OnFixedUpdate;
            }
        }
    
    #13622

    Gavalakis
    Keymaster

    These are pretty good 🙂 Thanks for sharing.
    You can also use the “ScriptControl/ExecuteFunction” to call “RigidBody.AddForce” or other Rigidbody function of course.

    #13639

    AVOlight
    Participant

    Thank you both for your help 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.