Pulling rotation adjustment, newton's third law, entitycoordinates for moveto (#5141)

* Pulling: Piano door stuck prevention (pulling angle-snap) and getting rid of a condition causing oddities with pull-to-location

* Pulling: Implement Newton's Third Law in regards to puller/pullee physics

Weightless condition was determined not to be necessary

* Fix pull-to-position on actively rotating/moving grids + fixes for rebase
This commit is contained in:
20kdc
2021-11-07 02:16:49 +00:00
committed by GitHub
parent 900f3e798d
commit 206f054cdf
5 changed files with 32 additions and 18 deletions

View File

@@ -65,15 +65,17 @@ namespace Content.Server.Physics.Controllers
continue; continue;
} }
if (pullable.Puller == null) var puller = pullable.Puller;
if (puller == null)
{ {
continue; continue;
} }
// Now that's over with... // Now that's over with...
var pullerPosition = pullable.Puller!.Transform.MapPosition; var pullerPosition = puller.Transform.MapPosition;
if (pullable.MovingTo.Value.MapId != pullerPosition.MapId) var movingTo = pullable.MovingTo.Value.ToMap(pullable.Owner.EntityManager);
if (movingTo.MapId != pullerPosition.MapId)
{ {
_pullableSystem.StopMoveTo(pullable); _pullableSystem.StopMoveTo(pullable);
continue; continue;
@@ -81,13 +83,13 @@ namespace Content.Server.Physics.Controllers
if (!pullable.Owner.TryGetComponent<PhysicsComponent>(out var physics) || if (!pullable.Owner.TryGetComponent<PhysicsComponent>(out var physics) ||
physics.BodyType == BodyType.Static || physics.BodyType == BodyType.Static ||
pullable.MovingTo.Value.MapId != pullable.Owner.Transform.MapID) movingTo.MapId != pullable.Owner.Transform.MapID)
{ {
_pullableSystem.StopMoveTo(pullable); _pullableSystem.StopMoveTo(pullable);
continue; continue;
} }
var movingPosition = pullable.MovingTo.Value.Position; var movingPosition = movingTo.Position;
var ownerPosition = pullable.Owner.Transform.MapPosition.Position; var ownerPosition = pullable.Owner.Transform.MapPosition.Position;
var diff = movingPosition - ownerPosition; var diff = movingPosition - ownerPosition;
@@ -113,7 +115,14 @@ namespace Content.Server.Physics.Controllers
accel -= physics.LinearVelocity * SettleShutdownMultiplier * scaling; accel -= physics.LinearVelocity * SettleShutdownMultiplier * scaling;
} }
physics.WakeBody(); physics.WakeBody();
physics.ApplyLinearImpulse(accel * physics.Mass * frameTime); var impulse = accel * physics.Mass * frameTime;
physics.ApplyLinearImpulse(impulse);
if (puller.TryGetComponent<PhysicsComponent>(out var pullerPhysics))
{
pullerPhysics.WakeBody();
pullerPhysics.ApplyLinearImpulse(-impulse);
}
} }
} }
} }

View File

@@ -36,7 +36,7 @@ namespace Content.Shared.Pulling.Components
public bool BeingPulled => Puller != null; public bool BeingPulled => Puller != null;
public MapCoordinates? MovingTo { get; set; } public EntityCoordinates? MovingTo { get; set; }
public override ComponentState GetComponentState(ICommonSession player) public override ComponentState GetComponentState(ICommonSession player)
{ {

View File

@@ -140,7 +140,7 @@ namespace Content.Shared.Pulling
ForceRelationship(null, pullable); ForceRelationship(null, pullable);
} }
public void ForceSetMovingTo(SharedPullableComponent pullable, MapCoordinates? movingTo) public void ForceSetMovingTo(SharedPullableComponent pullable, EntityCoordinates? movingTo)
{ {
if (pullable.MovingTo == movingTo) if (pullable.MovingTo == movingTo)
{ {

View File

@@ -172,7 +172,7 @@ namespace Content.Shared.Pulling
return true; return true;
} }
public bool TryMoveTo(SharedPullableComponent pullable, MapCoordinates to) public bool TryMoveTo(SharedPullableComponent pullable, EntityCoordinates to)
{ {
if (pullable.Puller == null) if (pullable.Puller == null)
{ {

View File

@@ -47,8 +47,9 @@ namespace Content.Shared.Pulling
/// If difference between puller and pulled angle lower that this threshold, /// If difference between puller and pulled angle lower that this threshold,
/// pulled entity will not change its rotation. /// pulled entity will not change its rotation.
/// Helps with diagonal movement jittering /// Helps with diagonal movement jittering
/// As of further adjustments, should divide cleanly into 90 degrees
/// </summary> /// </summary>
private const float ThresholdRotAngle = 30; private const float ThresholdRotAngle = 22.5f;
public IReadOnlySet<SharedPullableComponent> Moving => _moving; public IReadOnlySet<SharedPullableComponent> Moving => _moving;
@@ -177,11 +178,6 @@ namespace Content.Shared.Pulling
UpdatePulledRotation(puller, pulled); UpdatePulledRotation(puller, pulled);
physics.WakeBody(); physics.WakeBody();
if (pulled.TryGetComponent(out SharedPullableComponent? pullable))
{
_pullSm.ForceSetMovingTo(pullable, null);
}
} }
// TODO: When Joint networking is less shitcodey fix this to use a dedicated joints message. // TODO: When Joint networking is less shitcodey fix this to use a dedicated joints message.
@@ -224,7 +220,7 @@ namespace Content.Shared.Pulling
return false; return false;
} }
TryMoveTo(pullable, coords.ToMap(EntityManager)); TryMoveTo(pullable, coords);
return false; return false;
} }
@@ -270,8 +266,17 @@ namespace Content.Shared.Pulling
var newAngle = Angle.FromWorldVec(dir); var newAngle = Angle.FromWorldVec(dir);
var diff = newAngle - oldAngle; var diff = newAngle - oldAngle;
if (Math.Abs(diff.Degrees) > ThresholdRotAngle) if (Math.Abs(diff.Degrees) > (ThresholdRotAngle / 2f))
pulled.Transform.WorldRotation = newAngle; {
// Ok, so this bit is difficult because ideally it would look like it's snapping to sane angles.
// Otherwise PIANO DOOR STUCK! happens.
// But it also needs to work with station rotation / align to the local parent.
// So...
var baseRotation = pulled.Transform.Parent?.WorldRotation ?? 0f;
var localRotation = newAngle - baseRotation;
var localRotationSnapped = Angle.FromDegrees(Math.Floor((localRotation.Degrees / ThresholdRotAngle) + 0.5f) * ThresholdRotAngle);
pulled.Transform.LocalRotation = localRotationSnapped;
}
} }
} }
} }