Skip to content

Commit

Permalink
I guess we're doing impulses now
Browse files Browse the repository at this point in the history
  • Loading branch information
Mnemotechnician committed Sep 7, 2024
1 parent 922211c commit fae94da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public sealed partial class PullerComponent : Component
/// The specific force of pushing, in newtons per kilogram. This is multiplied by the puller's physics mass.
/// </summary>
[DataField]
public float SpecificForce = 2.5f;
public float SpecificForce = 0.3f;

/// <summary>
/// The maximum distance between the puller and the point towards which the puller may attempt to pull it, in meters.
Expand Down
8 changes: 5 additions & 3 deletions Content.Shared/Movement/Pulling/Systems/PullingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ public override void Update(float frameTime)
}

var desiredDeltaPos = pushCoordinates.Position - Transform(pulled).Coordinates.ToMapPos(EntityManager, _xformSys);
var desiredForce = pulledPhysics.Mass * desiredDeltaPos * 60;
var desiredForce = pulledPhysics.Mass * desiredDeltaPos;
var maxSourceForce = pullerComp.SpecificForce * pullerPhysics.Mass;
var actualForce = desiredForce.LengthSquared() > maxSourceForce * maxSourceForce ? desiredDeltaPos.Normalized() * maxSourceForce : desiredForce;

_physics.ApplyForce(pulled, actualForce);
_physics.ApplyForce(puller, -actualForce);
// Cannot use ApplyForce here because it will be cleared on the next physics substep which will render it ultimately useless
// The alternative is to run this function on every physics substep, but that is way too expensive for such a minor system
_physics.ApplyLinearImpulse(pulled, actualForce);
_physics.ApplyLinearImpulse(puller, -actualForce);
pulledComp.BeingActivelyPushed = true;

// Means the pullee has been pushed close enough to the destination
Expand Down

0 comments on commit fae94da

Please sign in to comment.