Re-implement recoil (#9406)
* Re-implement recoil Playing around with the values atm * Update constants * final tweaks
This commit is contained in:
32
Content.Client/Camera/CameraRecoilSystem.cs
Normal file
32
Content.Client/Camera/CameraRecoilSystem.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Content.Shared.Camera;
|
||||
|
||||
namespace Content.Client.Camera;
|
||||
|
||||
public sealed class CameraRecoilSystem : SharedCameraRecoilSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<CameraKickEvent>(OnCameraKick);
|
||||
}
|
||||
|
||||
private void OnCameraKick(CameraKickEvent ev)
|
||||
{
|
||||
KickCamera(ev.Euid, ev.Recoil);
|
||||
}
|
||||
|
||||
public override void KickCamera(EntityUid uid, Vector2 recoil, CameraRecoilComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false)) return;
|
||||
|
||||
// Use really bad math to "dampen" kicks when we're already kicked.
|
||||
var existing = component.CurrentKick.Length;
|
||||
var dampen = existing / KickMagnitudeMax;
|
||||
component.CurrentKick += recoil * (1 - dampen);
|
||||
|
||||
if (component.CurrentKick.Length > KickMagnitudeMax)
|
||||
component.CurrentKick = component.CurrentKick.Normalized * KickMagnitudeMax;
|
||||
|
||||
component.LastKickTime = 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user