changed: changing some air movement values can now be smoothed (including values that are used to smoothing out inputs)
This commit is contained in:
@@ -44,6 +44,7 @@ namespace Reset.Units{
|
||||
public float gravityMax = 8f;
|
||||
public float gravityAcceleration = 1f;
|
||||
public float gravityScale = 1f;
|
||||
public float settingsChangeSmoothing = 6f;
|
||||
|
||||
// Rotation
|
||||
[ShowInInspector, SerializeReference]
|
||||
@@ -72,6 +73,12 @@ namespace Reset.Units{
|
||||
[ShowInInspector, ReadOnly] private Quaternion specifiedRotation;
|
||||
[ShowInInspector, ReadOnly] private float outputRotationSpeed;
|
||||
|
||||
// Used by graph to gradually shift into new values rather than dump them. Even if they're smoothed values they need to be eased into
|
||||
[ShowInInspector, ReadOnly] private float outputJumpDecay;
|
||||
[ShowInInspector, ReadOnly] private float outputGravityAccel;
|
||||
[ShowInInspector, ReadOnly] private float outputGravityScale;
|
||||
[ShowInInspector, ReadOnly] private float settingsChangeRotationSpeed;
|
||||
|
||||
private float directionChangeDot;
|
||||
private bool moveCallDisabledNextFrame;
|
||||
|
||||
@@ -204,7 +211,7 @@ namespace Reset.Units{
|
||||
// Update the gravity, called every frame
|
||||
private void UpdateCurrentGravity(){
|
||||
// Accelerate gravity
|
||||
// data.gravityPower += data.gravityAcceleration * Time.deltaTime;
|
||||
data.gravityPower += outputGravityAccel * Time.deltaTime;
|
||||
data.gravityPower = Mathf.Clamp(data.gravityPower, Mathf.NegativeInfinity, data.gravityMax);
|
||||
|
||||
// Apply a constant gravity if the player is grounded
|
||||
@@ -263,7 +270,7 @@ namespace Reset.Units{
|
||||
}
|
||||
|
||||
// Calculate rotation speed, as in how fast the fella rotates. This value has it's own smoothing to allow for gradual increasing/decreasing of the speed till it reaches the target
|
||||
outputRotationSpeed = Mathf.Lerp(outputRotationSpeed, data.rotationSpeed, data.rotationSmoothing * Time.deltaTime);
|
||||
outputRotationSpeed = Mathf.Lerp(outputRotationSpeed, data.rotationSpeed, settingsChangeRotationSpeed * Time.deltaTime);
|
||||
|
||||
// Set final rotation
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, outputRotation, outputRotationSpeed * Time.deltaTime).Flatten(0, null, 0);
|
||||
@@ -298,7 +305,7 @@ namespace Reset.Units{
|
||||
|
||||
// Add their related speeds
|
||||
moveXZDir *= speed * Time.deltaTime;
|
||||
moveYDir *= gravityScale * Time.deltaTime;
|
||||
moveYDir *= outputGravityScale * Time.deltaTime;
|
||||
addDir *= additionalSpeed * Time.deltaTime;
|
||||
|
||||
// Construct the direction and move
|
||||
@@ -314,6 +321,14 @@ namespace Reset.Units{
|
||||
void LateUpdate(){
|
||||
UpdateGravityLate();
|
||||
DecayAdditionalDirection();
|
||||
SmoothingSettingsChanges();
|
||||
}
|
||||
|
||||
private void SmoothingSettingsChanges(){
|
||||
outputJumpDecay = Mathf.Lerp(outputJumpDecay, data.jumpPowerDecay, data.settingsChangeSmoothing * Time.deltaTime);
|
||||
outputGravityAccel = Mathf.Lerp(outputGravityAccel, data.gravityAcceleration, data.settingsChangeSmoothing * Time.deltaTime);
|
||||
outputGravityScale = Mathf.Lerp(outputGravityScale, data.gravityScale, data.settingsChangeSmoothing * Time.deltaTime);
|
||||
settingsChangeRotationSpeed = Mathf.Lerp(settingsChangeRotationSpeed, data.rotationSpeed, data.settingsChangeSmoothing * Time.deltaTime);
|
||||
}
|
||||
|
||||
void DecayAdditionalDirection(){
|
||||
@@ -343,7 +358,7 @@ namespace Reset.Units{
|
||||
|
||||
private void UpdateGravityLate(){
|
||||
// Decay jump power
|
||||
data.jumpPower -= data.jumpPowerDecay * Time.deltaTime;
|
||||
data.jumpPower -= outputJumpDecay * Time.deltaTime;
|
||||
data.jumpPower = Mathf.Max(0f, data.jumpPower);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user