void FixedUpdate() { if (playerMovement.isPlayerGrounded()) { if (input.MouseAimHold) { targetBobAmount = bobbingAmountAimed; } else { targetBobAmount = bobbingAmountDefault; } float waveslice = 0.0f; float horizontal = input.Horizontal; float vertical = input.Vertical; if (Mathf.Abs(horizontal) == 0 && Mathf.Abs(vertical) == 0) { timer = 0.0f; } else { waveslice = Mathf.Sin(timer); if (input.IsRunning && stats.GetPlayerStamina() > 0f) { timer = timer + bobbingSpeedRun; } else { timer = timer + bobbingSpeedWalk; } if (timer > Mathf.PI * 2) { timer = timer - (Mathf.PI * 2); } } if (waveslice != 0) { float translateChange = waveslice * targetBobAmount; float totalAxes = Mathf.Abs(horizontal) + Mathf.Abs(vertical); totalAxes = Mathf.Clamp(totalAxes, -1.0f, 1.0f); translateChange = totalAxes * translateChange; headpos.y = midpointY + translateChange; headpos.x = midpointX + translateChange; } else { Mathf.Lerp(headpos.y, midpointY, 1f); Mathf.Lerp(headpos.x, -midpointX, 1f); } transform.localPosition = headpos; } }