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:
@@ -65,15 +65,17 @@ namespace Content.Server.Physics.Controllers
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pullable.Puller == null)
|
||||
var puller = pullable.Puller;
|
||||
if (puller == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Now that's over with...
|
||||
|
||||
var pullerPosition = pullable.Puller!.Transform.MapPosition;
|
||||
if (pullable.MovingTo.Value.MapId != pullerPosition.MapId)
|
||||
var pullerPosition = puller.Transform.MapPosition;
|
||||
var movingTo = pullable.MovingTo.Value.ToMap(pullable.Owner.EntityManager);
|
||||
if (movingTo.MapId != pullerPosition.MapId)
|
||||
{
|
||||
_pullableSystem.StopMoveTo(pullable);
|
||||
continue;
|
||||
@@ -81,13 +83,13 @@ namespace Content.Server.Physics.Controllers
|
||||
|
||||
if (!pullable.Owner.TryGetComponent<PhysicsComponent>(out var physics) ||
|
||||
physics.BodyType == BodyType.Static ||
|
||||
pullable.MovingTo.Value.MapId != pullable.Owner.Transform.MapID)
|
||||
movingTo.MapId != pullable.Owner.Transform.MapID)
|
||||
{
|
||||
_pullableSystem.StopMoveTo(pullable);
|
||||
continue;
|
||||
}
|
||||
|
||||
var movingPosition = pullable.MovingTo.Value.Position;
|
||||
var movingPosition = movingTo.Position;
|
||||
var ownerPosition = pullable.Owner.Transform.MapPosition.Position;
|
||||
|
||||
var diff = movingPosition - ownerPosition;
|
||||
@@ -113,7 +115,14 @@ namespace Content.Server.Physics.Controllers
|
||||
accel -= physics.LinearVelocity * SettleShutdownMultiplier * scaling;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace Content.Shared.Pulling.Components
|
||||
|
||||
public bool BeingPulled => Puller != null;
|
||||
|
||||
public MapCoordinates? MovingTo { get; set; }
|
||||
public EntityCoordinates? MovingTo { get; set; }
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace Content.Shared.Pulling
|
||||
ForceRelationship(null, pullable);
|
||||
}
|
||||
|
||||
public void ForceSetMovingTo(SharedPullableComponent pullable, MapCoordinates? movingTo)
|
||||
public void ForceSetMovingTo(SharedPullableComponent pullable, EntityCoordinates? movingTo)
|
||||
{
|
||||
if (pullable.MovingTo == movingTo)
|
||||
{
|
||||
|
||||
@@ -172,7 +172,7 @@ namespace Content.Shared.Pulling
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryMoveTo(SharedPullableComponent pullable, MapCoordinates to)
|
||||
public bool TryMoveTo(SharedPullableComponent pullable, EntityCoordinates to)
|
||||
{
|
||||
if (pullable.Puller == null)
|
||||
{
|
||||
|
||||
@@ -47,8 +47,9 @@ namespace Content.Shared.Pulling
|
||||
/// If difference between puller and pulled angle lower that this threshold,
|
||||
/// pulled entity will not change its rotation.
|
||||
/// Helps with diagonal movement jittering
|
||||
/// As of further adjustments, should divide cleanly into 90 degrees
|
||||
/// </summary>
|
||||
private const float ThresholdRotAngle = 30;
|
||||
private const float ThresholdRotAngle = 22.5f;
|
||||
|
||||
public IReadOnlySet<SharedPullableComponent> Moving => _moving;
|
||||
|
||||
@@ -177,11 +178,6 @@ namespace Content.Shared.Pulling
|
||||
UpdatePulledRotation(puller, pulled);
|
||||
|
||||
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.
|
||||
@@ -224,7 +220,7 @@ namespace Content.Shared.Pulling
|
||||
return false;
|
||||
}
|
||||
|
||||
TryMoveTo(pullable, coords.ToMap(EntityManager));
|
||||
TryMoveTo(pullable, coords);
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -270,8 +266,17 @@ namespace Content.Shared.Pulling
|
||||
var newAngle = Angle.FromWorldVec(dir);
|
||||
|
||||
var diff = newAngle - oldAngle;
|
||||
if (Math.Abs(diff.Degrees) > ThresholdRotAngle)
|
||||
pulled.Transform.WorldRotation = newAngle;
|
||||
if (Math.Abs(diff.Degrees) > (ThresholdRotAngle / 2f))
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user