Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frictionfull Space #514

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Content.Server/Station/Systems/StationDampeningSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Content.Server.Station.Events;
using Content.Shared.Physics;

namespace Content.Server.Station.Systems;

public sealed class StationDampeningSystem : EntitySystem
{
public override void Initialize()
{
SubscribeLocalEvent<StationPostInitEvent>(OnInitStation);
}

private void OnInitStation(ref StationPostInitEvent ev)
{
foreach (var grid in ev.Station.Comp.Grids)
{
// If the station grid doesn't have defined dampening, give it a small dampening by default
// This will ensure cargo tech pros won't fling the station 1000 megaparsec away from the galaxy
if (!TryComp<PassiveDampeningComponent>(grid, out var dampening))
{
dampening = AddComp<PassiveDampeningComponent>(grid);
dampening.Enabled = true;
dampening.LinearDampening = 0.01f;
dampening.AngularDampening = 0.01f;
}
}
}
}
13 changes: 11 additions & 2 deletions Content.Shared/Physics/FrictionRemoverSystem.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Robust.Shared.Map.Components;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Systems;
Expand All @@ -19,7 +20,15 @@ public override void Initialize()

private void RemoveDampening(EntityUid uid, PhysicsComponent component, PhysicsSleepEvent args)
{
_physics.SetAngularDamping(uid, component, 0f, false);
_physics.SetLinearDamping(uid, component, 0f);
var linear = 0f;
var angular = 0f;
if (TryComp<PassiveDampeningComponent>(uid, out var dampening) && dampening.Enabled)
{
linear = dampening.LinearDampening;
angular = dampening.AngularDampening;
}

_physics.SetAngularDamping(uid, component, angular, false);
_physics.SetLinearDamping(uid, component, linear);
}
}
18 changes: 18 additions & 0 deletions Content.Shared/Physics/PassiveDampeningComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Content.Shared.Physics;

/// <summary>
/// A component that allows an entity to have friction (linear and angular dampening)
/// even when not being affected by gravity.
/// </summary>
[RegisterComponent]
public sealed partial class PassiveDampeningComponent : Component
{
[DataField]
public bool Enabled = true;

[DataField]
public float LinearDampening = 0.2f;

[DataField]
public float AngularDampening = 0.2f;
}
3 changes: 3 additions & 0 deletions Resources/Maps/Shuttles/trading_outpost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ entities:
linearDamping: 0.05
fixedRotation: False
bodyType: Dynamic
- type: PassiveDampening # To prevent cargotechs from flingling it away.
linearDampening: 0.01
angularDampening: 0.01
- type: Fixtures
fixtures: {}
- type: OccluderTree
Expand Down
Loading