Forums › 💬 NodeCanvas › 🤩 Custom Nodes and Tasks › Physics tasks for adding torque and other physics forces › Reply To: Physics tasks for adding torque and other physics forces
I created a couple of custom ones awhile ago. Not sure if there is alternatives or better but here you go
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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; } } |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
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; } } |
