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:
@@ -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.Mobs;
|
||||||
using Content.Server.GameObjects.Components.Movement;
|
using Content.Server.GameObjects.Components.Movement;
|
||||||
using Content.Server.GameObjects.Components.Sound;
|
using Content.Server.GameObjects.Components.Sound;
|
||||||
@@ -131,16 +132,16 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
var physics = entity.GetComponent<PhysicsComponent>();
|
var physics = entity.GetComponent<PhysicsComponent>();
|
||||||
if (entity.TryGetComponent<CollidableComponent>(out var collider))
|
if (entity.TryGetComponent<CollidableComponent>(out var collider))
|
||||||
{
|
{
|
||||||
UpdateKinematics(entity.Transform, mover, physics, collider);
|
UpdateKinematics(entity.Transform, mover, physics, frameTime, collider);
|
||||||
}
|
}
|
||||||
else
|
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)
|
if (physics.Controller == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -83,7 +83,9 @@ namespace Content.Server.Throw
|
|||||||
physComp = thrownEnt.AddComponent<PhysicsComponent>();
|
physComp = thrownEnt.AddComponent<PhysicsComponent>();
|
||||||
|
|
||||||
var timing = IoCManager.Resolve<IGameTiming>();
|
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.SetController<ThrowController>();
|
||||||
(physComp.Controller as ThrowController)?.StartThrow(angle.ToVec() * spd);
|
(physComp.Controller as ThrowController)?.StartThrow(angle.ToVec() * spd);
|
||||||
@@ -146,10 +148,9 @@ namespace Content.Server.Throw
|
|||||||
|
|
||||||
var velocityNecessary = distance / throwDuration;
|
var velocityNecessary = distance / throwDuration;
|
||||||
var impulseNecessary = velocityNecessary * mass;
|
var impulseNecessary = velocityNecessary * mass;
|
||||||
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().
|
||||||
Throw(thrownEnt, MathF.Min(forceNecessary, throwForceMax), targetLoc, sourceLoc, spread, throwSourceEnt);
|
Throw(thrownEnt, MathF.Min(impulseNecessary, throwForceMax), targetLoc, sourceLoc, spread, throwSourceEnt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user