fix: corrected math for air directional jumping

This commit is contained in:
Chris
2025-07-15 18:15:00 -04:00
parent 0e0bb7d3e0
commit 577659458e

View File

@@ -53,7 +53,7 @@ namespace NodeCanvas.Tasks.Actions {
// Save current velocity and get current input direction // Save current velocity and get current input direction
Vector3 currentVelocityVector3 = new Vector3(agent.velocity.x, 0f, agent.velocity.z); Vector3 currentVelocityVector3 = new Vector3(agent.velocity.x, 0f, agent.velocity.z);
Vector2 currentInput = agent.GetComponent<PlayerControls>().rawMoveInput; Vector2 currentInput = agent.GetComponent<PlayerControls>().rawMoveInput;
Vector3 currentInputVector3 = Camera.main.transform.rotation.Flatten(0, null, 0) * new Vector3(currentInput.x, 0f, currentInput.y); Vector3 currentInputVector3 = new Vector3(currentInput.x, 0f, currentInput.y);
// Ignore rotation for the current velocity // Ignore rotation for the current velocity
Vector3 currentVelocityWorld = agent.transform.InverseTransformDirection(currentVelocityVector3.normalized); Vector3 currentVelocityWorld = agent.transform.InverseTransformDirection(currentVelocityVector3.normalized);
@@ -82,7 +82,7 @@ namespace NodeCanvas.Tasks.Actions {
remappedAirDirectionDot = Mathf.Clamp(remappedAirDirectionDot, 0f, 1f); remappedAirDirectionDot = Mathf.Clamp(remappedAirDirectionDot, 0f, 1f);
// Lerp between the current direction and the inputted direction based on the previous dot product // Lerp between the current direction and the inputted direction based on the previous dot product
Vector3 outputDirection = Vector3.Lerp(currentVelocityVector3.normalized, currentInputVector3.normalized, remappedAirDirectionDot); Vector3 outputDirection = Vector3.Lerp(currentInputVector3.normalized, currentVelocityVector3.normalized, remappedAirDirectionDot);
// If there is a direction force, lean into that based on it's strength // If there is a direction force, lean into that based on it's strength
outputDirection = Vector3.Lerp(outputDirection, directionalForce.value.normalized, directionalForceStrength.value).normalized; outputDirection = Vector3.Lerp(outputDirection, directionalForce.value.normalized, directionalForceStrength.value).normalized;
@@ -90,7 +90,10 @@ namespace NodeCanvas.Tasks.Actions {
// Extra math to degrade current air move direction by velocity inheritence, before applying new air direction // Extra math to degrade current air move direction by velocity inheritence, before applying new air direction
airMoveDirection.value *= currentVelocityInheritence.value; airMoveDirection.value *= currentVelocityInheritence.value;
// Set air move direciton // Account for the camera's rotation before setting it as the air move direction
outputDirection = Camera.main.transform.rotation.Flatten(0, null, 0) * outputDirection;
// Set air move direction
airMoveDirection.value += outputDirection * outputVelocity; airMoveDirection.value += outputDirection * outputVelocity;
} }