Fixes movement and throwing incorrect tick-rate scaling (#1162)

* fixes movement and throwing scaling incorrectly w/ tick rate

* Update Content.Server/GameObjects/EntitySystems/MoverSystem.cs
This commit is contained in:
Tyler Young
2020-06-24 12:41:31 -04:00
committed by GitHub
parent 623e47f19d
commit b92a2ba4e6
2 changed files with 9 additions and 7 deletions

View File

@@ -1,4 +1,5 @@
using Content.Server.GameObjects.Components;
using System;
using Content.Server.GameObjects.Components;
using Content.Server.GameObjects.Components.Mobs;
using Content.Server.GameObjects.Components.Movement;
using Content.Server.GameObjects.Components.Sound;
@@ -131,16 +132,16 @@ namespace Content.Server.GameObjects.EntitySystems
var physics = entity.GetComponent<PhysicsComponent>();
if (entity.TryGetComponent<CollidableComponent>(out var collider))
{
UpdateKinematics(entity.Transform, mover, physics, collider);
UpdateKinematics(entity.Transform, mover, physics, frameTime, collider);
}
else
{
UpdateKinematics(entity.Transform, mover, physics);
UpdateKinematics(entity.Transform, mover, physics, frameTime);
}
}
}
private void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, PhysicsComponent physics, CollidableComponent collider = null)
private void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, PhysicsComponent physics, float frameTime, CollidableComponent collider = null)
{
if (physics.Controller == null)
{

View File

@@ -83,7 +83,9 @@ namespace Content.Server.Throw
physComp = thrownEnt.AddComponent<PhysicsComponent>();
var timing = IoCManager.Resolve<IGameTiming>();
var spd = throwForce / (1f / timing.TickRate); // acceleration is applied in 1 tick instead of 1 second, scale appropriately
// scaling is handled elsewhere, this is just multiplying by 60 independent of timing as a fix until elsewhere values are updated
var spd = throwForce * 60;
physComp.SetController<ThrowController>();
(physComp.Controller as ThrowController)?.StartThrow(angle.ToVec() * spd);
@@ -146,10 +148,9 @@ namespace Content.Server.Throw
var velocityNecessary = distance / throwDuration;
var impulseNecessary = velocityNecessary * mass;
var forceNecessary = impulseNecessary * (1f / timing.TickRate);
// Then clamp it to the max force allowed and call Throw().
Throw(thrownEnt, MathF.Min(forceNecessary, throwForceMax), targetLoc, sourceLoc, spread, throwSourceEnt);
Throw(thrownEnt, MathF.Min(impulseNecessary, throwForceMax), targetLoc, sourceLoc, spread, throwSourceEnt);
}
}
}