Jetpacks (#9023)
* Movement acceleration * tweaks * Weightless refactor coz fuck it * CCVars * weightless movement tweaks * Some cleanup while I'm here * dorkpacks * thanks fork * fixes * zoomies * toggles * hmm * yamls * b * so true * Effects refactor * namespace * review
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
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 IMobMoverComponent? mobMover) || worldNormal == Vector2.Zero) return;
|
||||
|
||||
otherBody.ApplyLinearImpulse(-worldNormal * mobMover.PushStrength * frameTime);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user