Files
tbd-station-14/Content.Shared/Movement/Systems/SharedMoverController.Pushing.cs
metalgearsloth b9e876ca92 The real movement refactor (#9645)
* The real movement refactor

* ref events

* Jetpack cleanup

* a

* Vehicles partially working

* Balance tweaks

* Restore some shitcode

* AAAAAAAA

* Even more prediction

* ECS compstate trying to fix this

* yml

* vehicles kill me

* Don't lock keys

* a

* Fix problem

* Fix sounds

* shuttle inputs

* Shuttle controls

* space brakes

* Keybinds

* Fix merge

* Handle shutdown

* Fix keys

* Bump friction

* fix buckle offset

* Fix relay and friction

* Fix jetpack turning

* contexts amirite
2022-07-16 13:51:52 +10:00

57 lines
1.5 KiB
C#

using Content.Shared.CCVar;
using Content.Shared.Movement.Components;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
namespace Content.Shared.Movement.Systems;
public abstract partial class SharedMoverController
{
private bool _pushingEnabled;
private void InitializePushing()
{
_configManager.OnValueChanged(CCVars.MobPushing, SetPushing, true);
}
private void SetPushing(bool value)
{
if (_pushingEnabled == value) return;
_pushingEnabled = value;
if (_pushingEnabled)
{
_physics.KinematicControllerCollision += OnMobCollision;
}
else
{
_physics.KinematicControllerCollision -= OnMobCollision;
}
}
private void ShutdownPushing()
{
if (_pushingEnabled)
_physics.KinematicControllerCollision -= OnMobCollision;
_configManager.UnsubValueChanged(CCVars.MobPushing, SetPushing);
}
/// <summary>
/// Fake pushing for player collisions.
/// </summary>
private void OnMobCollision(Fixture ourFixture, Fixture otherFixture, float frameTime, Vector2 worldNormal)
{
if (!_pushingEnabled) return;
var otherBody = otherFixture.Body;
if (otherBody.BodyType != BodyType.Dynamic || !otherFixture.Hard) return;
if (!EntityManager.TryGetComponent(ourFixture.Body.Owner, out MobMoverComponent? mobMover) || worldNormal == Vector2.Zero) return;
otherBody.ApplyLinearImpulse(-worldNormal * mobMover.PushStrengthVV * frameTime);
}
}