maint: player FSM graph cleanup

This commit is contained in:
Chris
2025-03-12 18:27:51 -04:00
parent 29f57a47b0
commit 4cd6881374
17 changed files with 28 additions and 173 deletions

View File

@@ -9,8 +9,8 @@ using UnityEngine.InputSystem;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/Actions")]
public class Jump : ActionTask<CharacterController> {
[Category("Reset/Movement")]
public class AddJump : ActionTask<CharacterController> {
public BBParameter<float> jumpStrength;
public BBParameter<Vector3> airMoveDirection;
@@ -25,7 +25,15 @@ namespace NodeCanvas.Tasks.Actions {
public BBParameter<float> directionalForceStrength;
protected override string info {
get { return "Start Jump" ; }
get{
string dirStrength = "";
if (directionalForce.value != Vector3.zero && directionalForceStrength.value > 0f) {
dirStrength = $", towards <i>{directionalForce.value}</i> * {directionalForceStrength.value}";
}
return string.Format($"<b>Start Jump</b>, <i>{jumpStrength.value}</i> strength" + dirStrength);
}
}
//Use for initialization. This is called only once in the lifetime of the task.
@@ -40,50 +48,6 @@ namespace NodeCanvas.Tasks.Actions {
protected override void OnExecute(){
// Set jump power
jumpPower.value = jumpStrength.value;
{ /* // The following creates an air movement direction initially constructed from the agent's velocity, but also from subsequent jump inputs
// // Create a vector 3 to hold velocity without jump power or gravity
// Vector3 velocityWithoutY = new(agent.velocity.x, 0f, agent.velocity.z);
// Vector3 jumpLeapVelocity = new (velocityWithoutY.x, velocityWithoutY.y, velocityWithoutY.z);
//
// float inputVelocityMagnitude = velocityWithoutY.magnitude;
// float usableVelocity = 0f;
//
// // Ungrounded players can input a jump command to take their relative velcity as input for the new direction
// if(!agent.isGrounded){
// // Get raw input direction
// Vector3 playerInputVector3 = new(agent.GetComponent<PlayerControls>().rawMoveInput.x, 0f, agent.GetComponent<PlayerControls>().rawMoveInput.y);
//
// // Compare current velocity magnitude against jump strength. This is so air movement with no inherit velocity can be overidden by the new jump.
// usableVelocity = Mathf.Abs(velocityWithoutY.magnitude - jumpStrength.value);
// usableVelocity = Mathf.Max(usableVelocity, 0f);
// usableVelocity /= jumpStrength.value;
// // Debug.Log(usableVelocity);
//
// // Lerp between leaping and adding the full jump strenght, or adding a portion of it
// Vector3 fullNewValueVelocity = agent.transform.rotation * playerInputVector3.normalized * jumpStrength.value;
// Vector3 fullOriginalValueVelocity = velocityWithoutY;
//
// jumpLeapVelocity = Vector3.Lerp(fullNewValueVelocity, fullOriginalValueVelocity, 1f - usableVelocity);
// } else {
//
// }
//
// // Add directional force, for things such as wall bounces
// Vector3 directionalForceDirection = new Vector3(directionalForce.value.x, 0f, directionalForce.value.y);
// jumpLeapVelocity += (agent.transform.rotation * directionalForce.value) * directionalForceStrength.value;
//
//
// jumpLeapVelocity *= currentVelocityInheritence.value;
// if (agent.isGrounded){
// jumpLeapVelocity = Vector3.ClampMagnitude(jumpLeapVelocity, velocityWithoutY.magnitude);
// } else {
// jumpLeapVelocity = Vector3.ClampMagnitude(jumpLeapVelocity, Mathf.Lerp(velocityWithoutY.magnitude, jumpStrength.value, usableVelocity));
// }
//
// // Debug.Log(jumpLeapVelocity);
//
// airMoveDirection.value = jumpLeapVelocity; */ }
// Save current velocity and get current input direction
Vector3 currentVelocityVector3 = new Vector3(agent.velocity.x, 0f, agent.velocity.z);

View File

@@ -4,7 +4,7 @@ using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Core/Movement")]
[Category("Reset/Movement")]
public class CalculateAirMovement : ActionTask<Transform>{
public BBParameter<Vector3> airMoveDirection;
public BBParameter<Vector3> groundMoveDirection;

View File

@@ -5,9 +5,9 @@ using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Core/Movement")]
[Category("Reset/Movement")]
[Description("Unit flat ground movement")]
public class ProcessFlatLocomotion : ActionTask<CharacterController>{
public class CalculateGroundedLocomotion : ActionTask<CharacterController>{
public BBParameter<float> baseMoveSpeed;
public BBParameter<float> sprintAdditionalSpeed;

View File

@@ -5,7 +5,7 @@ using UnityEngine.InputSystem;
namespace NodeCanvas.Tasks.Conditions {
[Category("Core")]
[Category("Reset/Input")]
[Description("Check if input condition was matched this frame")]
public class CheckInput : ConditionTask<Transform>{
public BBParameter<string> actionName;

View File

@@ -1,67 +0,0 @@
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using ParadoxNotion.Services;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Core/Movement")]
public class ProcessGravity : ActionTask<CharacterController>{
public BBParameter<float> gravityScale = 1f;
public BBParameter<float> gravityAcceleration = 1f;
public BBParameter<float> gravityMax = 8f;
private Vector3 currentVelocity;
private bool freezeVelocity;
private float gravityPower;
//Use for initialization. This is called only once in the lifetime of the task.
//Return null if init was successfull. Return an error string otherwise
protected override string OnInit(){
MonoManager.current.onLateUpdate += LateUpdate;
return null;
}
//This is called once each time the task is enabled.
//Call EndAction() to mark the action as finished, either in success or failure.
//EndAction can be called from anywhere.
protected override void OnExecute() {
}
//Called once per frame while the action is active.
protected override void OnUpdate() {
if (!freezeVelocity && agent.velocity != Vector3.zero){
currentVelocity = new Vector3(agent.velocity.x, 0f, agent.velocity.y);
}
}
void LateUpdate(){
if (agent.isGrounded) {
gravityPower = 0f;
currentVelocity = Vector3.zero;
freezeVelocity = true;
agent.Move(Physics.gravity * .1f * Time.deltaTime);
} else {
if (currentVelocity == Vector3.zero && agent.velocity.y < 0f) {
freezeVelocity = false;
}
Debug.Log(currentVelocity);
agent.Move((Physics.gravity * gravityPower * Time.deltaTime));
}
}
//Called when the task is disabled.
protected override void OnStop() {
EndAction(true);
}
//Called when the task is paused.
protected override void OnPause() {
}
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 5c6c0f191ca8a3d4cb402d351413dff3

View File

@@ -6,7 +6,7 @@ using UnityEngine;
namespace NodeCanvas.Tasks.Actions {
[Category("Core/Movement")]
[Category("Reset/Movement")]
[Description("Finalizes movement and sends the final move commands to the controller")]
public class ProcessMovement : ActionTask<CharacterController>{
public BBParameter<Vector3> groundMoveDirection;

View File

@@ -22,9 +22,6 @@ public class PlayerControls : MonoBehaviour{
graph = GetComponent<GraphOwner>();
}
void Start(){
}
public void OnMove(InputValue value){
rawMoveInput.x = value.Get<Vector2>().x;
rawMoveInput.y = value.Get<Vector2>().y;
@@ -36,17 +33,10 @@ public class PlayerControls : MonoBehaviour{
}
public void OnSprint(){
SendMessage("StartSprint");
graph.SendEvent<string>("InputEvent", "Sprint", null);
}
public void OnJump(){
SendMessage("StartJump");
graph.SendEvent<string>("InputEvent", "Jump", null);
}
// Update is called once per frame
void Update(){
}
}