Fix throwing (#2345)

Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
metalgearsloth
2020-10-21 19:25:18 +11:00
committed by GitHub
parent 58f5c8e2b5
commit ea4a8c7e78

View File

@@ -1,5 +1,6 @@
using System;
using Content.Server.GameObjects.Components.Projectiles;
using Content.Shared.GameObjects.Components.Movement;
using Content.Shared.GameObjects.EntitySystems;
using Content.Shared.Physics;
using Robust.Shared.GameObjects.Components;
@@ -87,9 +88,7 @@ namespace Content.Server.Throw
throwSourceEnt.TryGetComponent<IPhysicsComponent>(out var physics) &&
physics.TryGetController(out ThrownController mover))
{
var physicsMgr = IoCManager.Resolve<IPhysicsManager>();
if (physicsMgr.IsWeightless(throwSourceEnt.Transform.Coordinates))
if (throwSourceEnt.IsWeightless())
{
// We don't check for surrounding entities,
// so you'll still get knocked around if you're hugging the station wall in zero g.
@@ -97,7 +96,7 @@ namespace Content.Server.Throw
// If somebody wants they can come along and make it so magboots completely hold you still.
// Would be a cool incentive to use them.
const float ThrowFactor = 5.0f; // Break Newton's Third Law for better gameplay
mover.Push(-angle.ToVec(), spd * ThrowFactor / physics.Mass);
mover.Push(-angle.ToVec(), spd * ThrowFactor * physics.InvMass);
}
}
}
@@ -138,15 +137,9 @@ namespace Content.Server.Throw
}
var throwDuration = ThrownItemComponent.DefaultThrowTime;
var mass = 1f;
if (thrownEnt.TryGetComponent(out IPhysicsComponent physics))
{
mass = physics.Mass;
}
// TODO: Mass isn't even used on the system side yet for controllers so do that someday
var velocityNecessary = distance / throwDuration;
var impulseNecessary = velocityNecessary * mass;
var forceNecessary = impulseNecessary * (1f / timing.TickRate);
var forceNecessary = velocityNecessary / timing.TickRate;
// Then clamp it to the max force allowed and call Throw().
thrownEnt.Throw(MathF.Min(forceNecessary, throwForceMax), targetLoc, sourceLoc, spread, throwSourceEnt);