fixed: more solid directional jumping

This commit is contained in:
Chris
2025-07-29 12:34:58 -04:00
parent 92c6ac0016
commit 7fbe05e39b

View File

@@ -10,19 +10,23 @@ using Reset.Player.Movement;
namespace NodeCanvas.Tasks.Actions {
[Category("Reset/Movement")]
public class AddJump : ActionTask<CharacterController> {
public BBParameter<float> jumpStrength;
public BBParameter<Vector3> airMoveDirection;
public BBParameter<float> jumpPower;
public BBParameter<PlayerFacingDirection> playerFacingDirection;
[Space(5)]
public BBParameter<float> jumpStrength;
[Range(0f, 1f)]
[SliderField(0, 1)]
public BBParameter<float> standStillJumpStrength;
public BBParameter<float> jumpPower;
[Tooltip("Determines how much current movement vectors into jump direction")]
[SliderField(0, 1)]
public BBParameter<float> currentVelocityInheritence;
public BBParameter<Vector3> directionalForce;
[SliderField(0, 1)]
public BBParameter<float> directionalForceStrength;
protected override string info {
@@ -72,9 +76,12 @@ namespace NodeCanvas.Tasks.Actions {
// Check threshold of current XZ velocity- if it's too close to zero, use the jumpStrength for jumping velocity. If it's not, use the current velocity
float velocityThreshold = 4f;
float magnitudeZeroDifference = Mathf.Clamp(currentVelocityVector3.magnitude - velocityThreshold, 0f, Mathf.Infinity) / velocityThreshold; // Divided by maximum to return a 0-1 value. Clamping not required.
float outputVelocity = Mathf.Lerp(jumpStrength.value, currentVelocityVector3.magnitude, Math.Clamp(magnitudeZeroDifference, 0f, 1f));
float outputHoritontalVelocity = Mathf.Lerp(jumpStrength.value, currentVelocityVector3.magnitude, Math.Clamp(magnitudeZeroDifference, 0f, 1f));
outputVelocity = Mathf.Min(outputVelocity, Mathf.Lerp(standStillJumpStrength.value * jumpStrength.value, jumpStrength.value * .4f, magnitudeZeroDifference));
outputHoritontalVelocity = Mathf.Min(outputHoritontalVelocity, Mathf.Lerp(standStillJumpStrength.value * jumpStrength.value, jumpStrength.value * .4f, magnitudeZeroDifference));
// Do the same for directional jump strength
outputHoritontalVelocity = Mathf.Lerp(outputHoritontalVelocity, jumpStrength.value, directionalForceStrength.value);
// Remap the dot to set -1 (opposing direction) to -.5f, and 1 (same direciton) to 1.2f
// This is done to allow some sideways jumping direction change, but none backwards, and all forwards
@@ -94,7 +101,7 @@ namespace NodeCanvas.Tasks.Actions {
outputDirection = Camera.main.transform.rotation.Flatten(0, null, 0) * outputDirection;
// Set air move direction
airMoveDirection.value += outputDirection * outputVelocity;
airMoveDirection.value += outputDirection * outputHoritontalVelocity;
}
EndAction(true);
}