Skip to content

Commit e45c878

Browse files
committed
Simplify
1 parent a6a3e14 commit e45c878

File tree

1 file changed

+7
-17
lines changed

1 file changed

+7
-17
lines changed

src/itemdrop.zig

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ pub const ItemDisplayManager = struct { // MARK: ItemDisplayManager
550550
var cameraFollowVel: Vec3f = @splat(0);
551551
const damping: Vec3f = @splat(130);
552552
var bobPhase: f32 = 0;
553-
var bobIntensity: f32 = 0;
554553

555554
pub fn update(deltaTime: f64) void {
556555
if (!settings.bobbing) {
@@ -581,16 +580,12 @@ pub const ItemDisplayManager = struct { // MARK: ItemDisplayManager
581580
const bobAmountLateral: f32 = 0.007;
582581
const bobAmountVertical: f32 = 0.006;
583582
const settleSpeed: f32 = 2.5;
584-
const fadeInSpeed: f32 = 0.4;
585-
const fadeOutSpeedOnGround: f32 = 2.5;
586-
const fadeOutSpeedAirborne: f32 = 0.4;
587583
const movementScaleMax: f32 = 10;
588584
const playerSpeedThreshold: f32 = 0.01;
589585
const movementScaleMinForPhase: f32 = 6;
590586

591587
if (game.Player.isFlying.load(.monotonic) or game.Player.isGhost.load(.monotonic)) {
592588
bobPhase = 0;
593-
bobIntensity = 0;
594589
return @splat(0);
595590
}
596591

@@ -602,23 +597,18 @@ pub const ItemDisplayManager = struct { // MARK: ItemDisplayManager
602597
const playerSpeed = vec.length(playerVel);
603598
const movementScale = @min(playerSpeed, movementScaleMax);
604599

605-
if (game.Player.onGround) {
606-
if (playerSpeed > playerSpeedThreshold) {
607-
bobPhase += dt*bobSpeed*@max(movementScale, movementScaleMinForPhase);
608-
bobPhase = std.math.mod(f32, bobPhase, 2*std.math.pi) catch unreachable;
609-
bobIntensity = std.math.lerp(bobIntensity, 1, @min(dt*fadeInSpeed, 1));
610-
} else {
611-
bobPhase = std.math.lerp(bobPhase, 0, @min(dt*settleSpeed, 1));
612-
bobIntensity = std.math.lerp(bobIntensity, 0, @min(dt*fadeOutSpeedOnGround, 1));
613-
}
600+
if (game.Player.onGround and playerSpeed > playerSpeedThreshold) {
601+
bobPhase += dt*bobSpeed*@max(movementScale, movementScaleMinForPhase);
602+
bobPhase = std.math.mod(f32, bobPhase, 2*std.math.pi) catch unreachable;
614603
} else {
615-
bobIntensity = std.math.lerp(bobIntensity, 0, @min(dt*fadeOutSpeedAirborne, 1));
604+
const targetPhase = std.math.round(bobPhase/std.math.pi)*std.math.pi;
605+
bobPhase = std.math.lerp(bobPhase, targetPhase, @min(dt*settleSpeed, 1));
616606
}
617607

618608
return .{
619-
@abs(std.math.sin(bobPhase))*bobAmountVertical*movementScale*bobIntensity,
609+
@abs(std.math.sin(bobPhase))*bobAmountVertical*movementScale,
620610
0,
621-
std.math.sin(bobPhase)*bobAmountLateral*movementScale*bobIntensity,
611+
std.math.sin(bobPhase)*bobAmountLateral*movementScale,
622612
};
623613
}
624614
};

0 commit comments

Comments
 (0)