Skip to content

Commit

Permalink
Physics speed limit (space-wizards#1344)
Browse files Browse the repository at this point in the history
Co-authored-by: Metal Gear Sloth <[email protected]>
  • Loading branch information
metalgearsloth and Metal Gear Sloth authored Oct 21, 2020
1 parent 9cc3c2c commit 4c69831
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Robust.Shared/GameObjects/Systems/SharedPhysicsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public abstract class SharedPhysicsSystem : EntitySystem
/// </summary>
private readonly HashSet<IPhysicsComponent> _deferredUpdates = new HashSet<IPhysicsComponent>();

// CVars aren't replicated to client (yet) so not using a cvar server-side for this.
private float _speedLimit = 30.0f;

public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -375,6 +378,11 @@ private void UpdatePosition(IPhysicsComponent physics, float frameTime)

physics.Owner.Transform.DeferUpdates = true;
_deferredUpdates.Add(physics);

// Slow zone up in here
if (physics.LinearVelocity.Length > _speedLimit)
physics.LinearVelocity = physics.LinearVelocity.Normalized * _speedLimit;

physics.WorldRotation += physics.AngularVelocity * frameTime;
physics.WorldPosition += physics.LinearVelocity * frameTime;
}
Expand Down

0 comments on commit 4c69831

Please sign in to comment.