Smoother Screenshake Reduction (#8310)
* Smoother Screenshake Reduction Screen shake will now always reach 0 no matter the intensity or duration without being cut off early. * Keep the max reduction rate
This commit is contained in:
@@ -72,6 +72,8 @@ public class Renderer implements ApplicationListener{
|
|||||||
landPTimer,
|
landPTimer,
|
||||||
//intensity for screen shake
|
//intensity for screen shake
|
||||||
shakeIntensity,
|
shakeIntensity,
|
||||||
|
//reduction rate of screen shake
|
||||||
|
shakeReduction,
|
||||||
//current duration of screen shake
|
//current duration of screen shake
|
||||||
shakeTime;
|
shakeTime;
|
||||||
//for landTime > 0: if true, core is currently *launching*, otherwise landing.
|
//for landTime > 0: if true, core is currently *launching*, otherwise landing.
|
||||||
@@ -83,14 +85,15 @@ public class Renderer implements ApplicationListener{
|
|||||||
Shaders.init();
|
Shaders.init();
|
||||||
|
|
||||||
Events.on(ResetEvent.class, e -> {
|
Events.on(ResetEvent.class, e -> {
|
||||||
shakeTime = shakeIntensity = 0f;
|
shakeTime = shakeIntensity = shakeReduction = 0f;
|
||||||
camShakeOffset.setZero();
|
camShakeOffset.setZero();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shake(float intensity, float duration){
|
public void shake(float intensity, float duration){
|
||||||
shakeIntensity = Math.max(shakeIntensity, intensity);
|
shakeIntensity = Math.max(shakeIntensity, Mathf.clamp(intensity, 0, 100));
|
||||||
shakeTime = Math.max(shakeTime, duration);
|
shakeTime = Math.max(shakeTime, duration);
|
||||||
|
shakeReduction = Math.max(shakeReduction, shakeIntensity / shakeTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEnvRenderer(int mask, Runnable render){
|
public void addEnvRenderer(int mask, Runnable render){
|
||||||
@@ -210,7 +213,7 @@ public class Renderer implements ApplicationListener{
|
|||||||
float intensity = shakeIntensity * (settings.getInt("screenshake", 4) / 4f) * 0.75f;
|
float intensity = shakeIntensity * (settings.getInt("screenshake", 4) / 4f) * 0.75f;
|
||||||
camShakeOffset.setToRandomDirection().scl(Mathf.random(intensity));
|
camShakeOffset.setToRandomDirection().scl(Mathf.random(intensity));
|
||||||
camera.position.add(camShakeOffset);
|
camera.position.add(camShakeOffset);
|
||||||
shakeIntensity -= 0.25f * Time.delta;
|
shakeIntensity -= shakeReduction * Time.delta;
|
||||||
shakeTime -= Time.delta;
|
shakeTime -= Time.delta;
|
||||||
shakeIntensity = Mathf.clamp(shakeIntensity, 0f, 100f);
|
shakeIntensity = Mathf.clamp(shakeIntensity, 0f, 100f);
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Reference in New Issue
Block a user