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