Make humans move based on their last grid's angle (#5122)
* Make humans move based on their last grid's angle * Fix ghost movement, fix weightless grid parenting * Make sure to init the last grid angle without needing to move
This commit is contained in:
@@ -87,6 +87,8 @@ namespace Content.Server.AI.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Angle LastGridAngle { get => Angle.Zero; set {} }
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public float PushStrength { get; set; } = IMobMoverComponent.PushStrengthDefault;
|
public float PushStrength { get; set; } = IMobMoverComponent.PushStrengthDefault;
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ namespace Content.Shared.Movement.Components
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
bool Sprinting { get; }
|
bool Sprinting { get; }
|
||||||
|
|
||||||
|
Angle LastGridAngle { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculated linear velocity direction of the entity.
|
/// Calculated linear velocity direction of the entity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ namespace Content.Shared.Movement.Components
|
|||||||
public float CurrentWalkSpeed => 0f;
|
public float CurrentWalkSpeed => 0f;
|
||||||
public float CurrentSprintSpeed => 0f;
|
public float CurrentSprintSpeed => 0f;
|
||||||
|
|
||||||
|
public Angle LastGridAngle { get => Angle.Zero; set {} }
|
||||||
|
|
||||||
public bool Sprinting => false;
|
public bool Sprinting => false;
|
||||||
public (Vector2 walking, Vector2 sprinting) VelocityDir => (Vector2.Zero, Vector2.Zero);
|
public (Vector2 walking, Vector2 sprinting) VelocityDir => (Vector2.Zero, Vector2.Zero);
|
||||||
|
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ namespace Content.Shared.Movement.Components
|
|||||||
|
|
||||||
private MoveButtons _heldMoveButtons = MoveButtons.None;
|
private MoveButtons _heldMoveButtons = MoveButtons.None;
|
||||||
|
|
||||||
|
public Angle LastGridAngle { get; set; } = new(0);
|
||||||
|
|
||||||
public float CurrentWalkSpeed => _movementSpeed?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
|
public float CurrentWalkSpeed => _movementSpeed?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
|
||||||
|
|
||||||
public float CurrentSprintSpeed => _movementSpeed?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
|
public float CurrentSprintSpeed => _movementSpeed?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
|
||||||
@@ -117,6 +119,7 @@ namespace Content.Shared.Movement.Components
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
Owner.EnsureComponentWarn<PhysicsComponent>();
|
Owner.EnsureComponentWarn<PhysicsComponent>();
|
||||||
|
LastGridAngle = Owner.Transform.Parent?.WorldRotation ?? new Angle(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -67,16 +67,21 @@ namespace Content.Shared.Movement
|
|||||||
{
|
{
|
||||||
var (walkDir, sprintDir) = mover.VelocityDir;
|
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||||
|
|
||||||
|
var transform = mover.Owner.Transform;
|
||||||
|
|
||||||
// Regular movement.
|
// Regular movement.
|
||||||
// Target velocity.
|
// Target velocity.
|
||||||
var total = (walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed);
|
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
|
||||||
|
|
||||||
var worldTotal = _relativeMovement ? new Angle(mover.Owner.Transform.Parent!.WorldRotation.Theta).RotateVec(total) : total;
|
var worldTotal = _relativeMovement ? transform.Parent!.WorldRotation.RotateVec(total) : total;
|
||||||
|
|
||||||
|
if (transform.GridID == GridId.Invalid)
|
||||||
|
worldTotal = mover.LastGridAngle.RotateVec(worldTotal);
|
||||||
|
else
|
||||||
|
mover.LastGridAngle = transform.Parent!.WorldRotation;
|
||||||
|
|
||||||
if (worldTotal != Vector2.Zero)
|
if (worldTotal != Vector2.Zero)
|
||||||
{
|
transform.WorldRotation = worldTotal.GetDir().ToAngle();
|
||||||
mover.Owner.Transform.WorldRotation = worldTotal.GetDir().ToAngle();
|
|
||||||
}
|
|
||||||
|
|
||||||
physicsComponent.LinearVelocity = worldTotal;
|
physicsComponent.LinearVelocity = worldTotal;
|
||||||
}
|
}
|
||||||
@@ -111,6 +116,8 @@ namespace Content.Shared.Movement
|
|||||||
|
|
||||||
if (!touching)
|
if (!touching)
|
||||||
{
|
{
|
||||||
|
if (transform.GridID != GridId.Invalid)
|
||||||
|
mover.LastGridAngle = transform.Parent!.WorldRotation;
|
||||||
transform.WorldRotation = physicsComponent.LinearVelocity.GetDir().ToAngle();
|
transform.WorldRotation = physicsComponent.LinearVelocity.GetDir().ToAngle();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -119,18 +126,19 @@ namespace Content.Shared.Movement
|
|||||||
// Regular movement.
|
// Regular movement.
|
||||||
// Target velocity.
|
// Target velocity.
|
||||||
// This is relative to the map / grid we're on.
|
// This is relative to the map / grid we're on.
|
||||||
var total = (walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed);
|
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
|
||||||
|
|
||||||
var worldTotal = _relativeMovement ?
|
var worldTotal = _relativeMovement ? transform.Parent!.WorldRotation.RotateVec(total) : total;
|
||||||
new Angle(transform.Parent!.WorldRotation.Theta).RotateVec(total) :
|
|
||||||
total;
|
|
||||||
|
|
||||||
DebugTools.Assert(MathHelper.CloseToPercent(total.Length, worldTotal.Length));
|
DebugTools.Assert(MathHelper.CloseToPercent(total.Length, worldTotal.Length));
|
||||||
|
|
||||||
if (weightless)
|
if (weightless)
|
||||||
{
|
|
||||||
worldTotal *= mobMover.WeightlessStrength;
|
worldTotal *= mobMover.WeightlessStrength;
|
||||||
}
|
|
||||||
|
if (transform.GridID == GridId.Invalid)
|
||||||
|
worldTotal = mover.LastGridAngle.RotateVec(worldTotal);
|
||||||
|
else
|
||||||
|
mover.LastGridAngle = transform.Parent!.WorldRotation;
|
||||||
|
|
||||||
if (worldTotal != Vector2.Zero)
|
if (worldTotal != Vector2.Zero)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user