Fixes CameraRecoil runtime (#2662)

Co-authored-by: Paul <ritter.paul1+git@googlemail.com>
This commit is contained in:
Paul Ritter
2020-12-01 20:41:16 +01:00
committed by GitHub
parent 0812233f20
commit 71aaf54595

View File

@@ -1,7 +1,9 @@
using System; #nullable enable
using System;
using Content.Shared.GameObjects.Components.Mobs; using Content.Shared.GameObjects.Components.Mobs;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.ComponentDependencies;
using Robust.Shared.Interfaces.Network; using Robust.Shared.Interfaces.Network;
using Robust.Shared.Log; using Robust.Shared.Log;
using Robust.Shared.Maths; using Robust.Shared.Maths;
@@ -28,19 +30,13 @@ namespace Content.Client.GameObjects.Components.Mobs
private Vector2 _currentKick; private Vector2 _currentKick;
private float _lastKickTime; private float _lastKickTime;
private EyeComponent _eye; [ComponentDependency]
private readonly EyeComponent? _eye;
// Basically I needed a way to chain this effect for the attack lunge animation. // Basically I needed a way to chain this effect for the attack lunge animation.
// Sorry! // Sorry!
public Vector2 BaseOffset { get; set; } public Vector2 BaseOffset { get; set; }
public override void Initialize()
{
base.Initialize();
_eye = Owner.GetComponent<EyeComponent>();
}
public override void Kick(Vector2 recoil) public override void Kick(Vector2 recoil)
{ {
if (float.IsNaN(recoil.X) || float.IsNaN(recoil.Y)) if (float.IsNaN(recoil.X) || float.IsNaN(recoil.Y))
@@ -62,7 +58,7 @@ namespace Content.Client.GameObjects.Components.Mobs
_updateEye(); _updateEye();
} }
public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null) public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession? session = null)
{ {
base.HandleNetworkMessage(message, channel, session); base.HandleNetworkMessage(message, channel, session);
@@ -86,7 +82,7 @@ namespace Content.Client.GameObjects.Components.Mobs
// Continually restore camera to 0. // Continually restore camera to 0.
var normalized = _currentKick.Normalized; var normalized = _currentKick.Normalized;
_lastKickTime += frameTime; _lastKickTime += frameTime;
var restoreRate = MathHelper.Lerp(RestoreRateMin, RestoreRateMax, Math.Min(1, _lastKickTime/RestoreRateRamp)); var restoreRate = MathHelper.Lerp(RestoreRateMin, RestoreRateMax, Math.Min(1, _lastKickTime/RestoreRateRamp));
var restore = normalized * restoreRate * frameTime; var restore = normalized * restoreRate * frameTime;
var (x, y) = _currentKick - restore; var (x, y) = _currentKick - restore;
@@ -107,7 +103,7 @@ namespace Content.Client.GameObjects.Components.Mobs
private void _updateEye() private void _updateEye()
{ {
_eye.Offset = BaseOffset + _currentKick; if (_eye != null) _eye.Offset = BaseOffset + _currentKick;
} }
} }
} }