Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Add zero length direction check
Browse files Browse the repository at this point in the history
  • Loading branch information
TheArturZh authored and rbertoche committed Oct 18, 2023
1 parent 506cef1 commit 251d1da
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions Content.Shared/Climbing/Systems/ClimbSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,23 @@ private void Climb(EntityUid uid, EntityUid user, EntityUid climbable, bool sile
var (worldPos, worldRot) = _xformSystem.GetWorldPositionRotation(xform);
var worldDirection = _xformSystem.GetWorldPosition(climbable) - worldPos;
var distance = worldDirection.Length();
var parentRot = (worldRot - xform.LocalRotation);
// Need direction relative to climber's parent.
var localDirection = (-parentRot).RotateVec(worldDirection);

climbing.IsClimbing = true;
var climbDuration = TimeSpan.FromSeconds(distance / climbing.TransitionRate);
climbing.NextTransition = _timing.CurTime + climbDuration;

climbing.Direction = localDirection.Normalized() * climbing.TransitionRate;
if (distance > 0)
{
var parentRot = (worldRot - xform.LocalRotation);
// Need direction relative to climber's parent.
var localDirection = (-parentRot).RotateVec(worldDirection);
climbing.Direction = localDirection.Normalized() * climbing.TransitionRate;
}
else
{
climbing.Direction = Vector2.Zero;
}

Dirty(uid, climbing);

_audio.PlayPredicted(comp.FinishClimbSound, climbable, user);
Expand Down

0 comments on commit 251d1da

Please sign in to comment.