Fix issues with exploding items from own hand (#645)

* Fix crash in CameraRecoilComponent from NaN values

Doesn't proceed with camera shake if either component of recoil is NaN.

* Log NaN recoil value in CameraRecoilComponent

* Fix ExplosionHelper passing NaN recoil values when exploding from hand

With other commits CameraRecoilComponent now won't crash from NaN recoil values. Still want to fix this so explosions shake the camera. Just sets a value slightly greater than 0.0 for distance if it is (0.0, 0.0)
This commit is contained in:
moneyl
2020-02-08 14:46:12 -05:00
committed by GitHub
parent eb7c80ba7a
commit a2a3e5e2e4
2 changed files with 18 additions and 2 deletions

View File

@@ -20,6 +20,12 @@ namespace Content.Server.Explosions
{
public static class ExplosionHelper
{
/// <summary>
/// Distance used for camera shake when distance from explosion is (0.0, 0.0).
/// Avoids getting NaN values down the line from doing math on (0.0, 0.0).
/// </summary>
private static Vector2 _epicenterDistance = (0.1f, 0.1f);
public static void SpawnExplosion(GridCoordinates coords, int devastationRange, int heavyImpactRange, int lightImpactRange, int flashRange)
{
var tileDefinitionManager = IoCManager.Resolve<ITileDefinitionManager>();
@@ -130,8 +136,11 @@ namespace Content.Server.Explosions
var playerPos = player.AttachedEntity.Transform.WorldPosition;
var delta = coords.ToMapPos(mapManager) - playerPos;
var distance = delta.LengthSquared;
//Change if zero. Will result in a NaN later breaking camera shake if not changed
if (delta.EqualsApprox((0.0f, 0.0f)))
delta = _epicenterDistance;
var distance = delta.LengthSquared;
var effect = 1 / (1 + 0.2f * distance);
if (effect > 0.01f)
{