Skip to content

Commit

Permalink
Fix camera bob speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Helco committed Mar 21, 2024
1 parent d270881 commit 8a67b08
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions zzre/game/systems/camera/DuelCamera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,22 +144,23 @@ private float GetClipDistance(Vector3 zeroDistPos, Vector3 targetPos, float dirS

private float UpdateBobbing(float elapsedTime)
{
var newCamPos = camera.Location.GlobalPosition with { Y = 0f };
if (isFirstFrame)
{
isFirstFrame = false;
totalCamTravel = 0f;
}
else
{
var lastTravel = (oldCamPos - camera.Location.GlobalPosition).Length();
var lastSpeed = lastTravel / elapsedTime;
var lastTravel = (oldCamPos - newCamPos).Length();
var lastSpeed = lastTravel * elapsedTime / 60; // this adds (unoriginal) framerate-independence
if (lastSpeed < MinimumCameraBobSpeed)
lastTravel = SimulatedBobSpeed * elapsedTime;
totalCamTravel += lastTravel * BobDistanceFactor;
lastSpeed = SimulatedBobSpeed * elapsedTime;
totalCamTravel += MathF.Floor(lastSpeed * BobDistanceFactor);
if (totalCamTravel > TotalBobTravel)
totalCamTravel -= TotalBobTravel;
}
oldCamPos = camera.Location.GlobalPosition;
oldCamPos = newCamPos;
return MathF.Sin(totalCamTravel * BobCycle);
}
}

0 comments on commit 8a67b08

Please sign in to comment.