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:
@@ -67,16 +67,21 @@ namespace Content.Shared.Movement
|
||||
{
|
||||
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||
|
||||
var transform = mover.Owner.Transform;
|
||||
|
||||
// Regular movement.
|
||||
// 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)
|
||||
{
|
||||
mover.Owner.Transform.WorldRotation = worldTotal.GetDir().ToAngle();
|
||||
}
|
||||
transform.WorldRotation = worldTotal.GetDir().ToAngle();
|
||||
|
||||
physicsComponent.LinearVelocity = worldTotal;
|
||||
}
|
||||
@@ -111,6 +116,8 @@ namespace Content.Shared.Movement
|
||||
|
||||
if (!touching)
|
||||
{
|
||||
if (transform.GridID != GridId.Invalid)
|
||||
mover.LastGridAngle = transform.Parent!.WorldRotation;
|
||||
transform.WorldRotation = physicsComponent.LinearVelocity.GetDir().ToAngle();
|
||||
return;
|
||||
}
|
||||
@@ -119,18 +126,19 @@ namespace Content.Shared.Movement
|
||||
// Regular movement.
|
||||
// Target velocity.
|
||||
// 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 ?
|
||||
new Angle(transform.Parent!.WorldRotation.Theta).RotateVec(total) :
|
||||
total;
|
||||
var worldTotal = _relativeMovement ? transform.Parent!.WorldRotation.RotateVec(total) : total;
|
||||
|
||||
DebugTools.Assert(MathHelper.CloseToPercent(total.Length, worldTotal.Length));
|
||||
|
||||
if (weightless)
|
||||
{
|
||||
worldTotal *= mobMover.WeightlessStrength;
|
||||
}
|
||||
|
||||
if (transform.GridID == GridId.Invalid)
|
||||
worldTotal = mover.LastGridAngle.RotateVec(worldTotal);
|
||||
else
|
||||
mover.LastGridAngle = transform.Parent!.WorldRotation;
|
||||
|
||||
if (worldTotal != Vector2.Zero)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user