fixed: more solid directional jumping
This commit is contained in:
@@ -10,19 +10,23 @@ using Reset.Player.Movement;
|
|||||||
namespace NodeCanvas.Tasks.Actions {
|
namespace NodeCanvas.Tasks.Actions {
|
||||||
[Category("Reset/Movement")]
|
[Category("Reset/Movement")]
|
||||||
public class AddJump : ActionTask<CharacterController> {
|
public class AddJump : ActionTask<CharacterController> {
|
||||||
public BBParameter<float> jumpStrength;
|
|
||||||
public BBParameter<Vector3> airMoveDirection;
|
public BBParameter<Vector3> airMoveDirection;
|
||||||
|
public BBParameter<float> jumpPower;
|
||||||
public BBParameter<PlayerFacingDirection> playerFacingDirection;
|
|
||||||
|
|
||||||
[Range(0f, 1f)]
|
[Space(5)]
|
||||||
|
public BBParameter<float> jumpStrength;
|
||||||
|
|
||||||
|
[SliderField(0, 1)]
|
||||||
public BBParameter<float> standStillJumpStrength;
|
public BBParameter<float> standStillJumpStrength;
|
||||||
|
|
||||||
public BBParameter<float> jumpPower;
|
|
||||||
|
|
||||||
[Tooltip("Determines how much current movement vectors into jump direction")]
|
[Tooltip("Determines how much current movement vectors into jump direction")]
|
||||||
|
[SliderField(0, 1)]
|
||||||
public BBParameter<float> currentVelocityInheritence;
|
public BBParameter<float> currentVelocityInheritence;
|
||||||
public BBParameter<Vector3> directionalForce;
|
public BBParameter<Vector3> directionalForce;
|
||||||
|
|
||||||
|
[SliderField(0, 1)]
|
||||||
public BBParameter<float> directionalForceStrength;
|
public BBParameter<float> directionalForceStrength;
|
||||||
|
|
||||||
protected override string info {
|
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
|
// 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 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 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));
|
||||||
|
|
||||||
|
outputHoritontalVelocity = Mathf.Min(outputHoritontalVelocity, Mathf.Lerp(standStillJumpStrength.value * jumpStrength.value, jumpStrength.value * .4f, magnitudeZeroDifference));
|
||||||
|
|
||||||
outputVelocity = Mathf.Min(outputVelocity, 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
|
// 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
|
// 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;
|
outputDirection = Camera.main.transform.rotation.Flatten(0, null, 0) * outputDirection;
|
||||||
|
|
||||||
// Set air move direction
|
// Set air move direction
|
||||||
airMoveDirection.value += outputDirection * outputVelocity;
|
airMoveDirection.value += outputDirection * outputHoritontalVelocity;
|
||||||
}
|
}
|
||||||
EndAction(true);
|
EndAction(true);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user