A camera noise effect named Punch that applies a damped rotational impulse to the camera. It initializes a spring-damped vector toward a target scaled by a Screenshake preference, updates the damping over time, decays its lifetime, and multiplies the camera world rotation by a small angle based on the damped value and a short life ramp.
namespace Sandbox.CameraNoise;
class Punch : BaseCameraNoise
{
float deathTime;
float lifeTime = 0.0f;
public Punch( Vector3 target, float time, float frequency, float damp )
{
damping.Current = target * GamePreferences.Screenshake;
damping.Target = 0;
damping.Frequency = frequency;
damping.Damping = damp;
deathTime = time;
}
public override bool IsDone => deathTime <= 0;
Vector3.SpringDamped damping;
public override void Update()
{
deathTime -= Time.Delta;
lifeTime += Time.Delta;
damping.Update( Time.Delta );
}
public override void ModifyCamera( CameraComponent cc )
{
var amount = lifeTime.Remap( 0, 0.3f, 0, 1 );
cc.WorldRotation *= new Angles( damping.Current * amount );
}
}