From c87ffeba29fb4c6fa07921eabff3c7fed9257f3c Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 13 Oct 2023 21:20:52 -0700 Subject: [PATCH] Loops: try to position player so hitbox edge touches loop radius Large enough momentum will still position the player beyond the loop radius initially. This is intentional so that there is no jerk when entering the loop. Without a more sophisticated algorithm to revolve asymmetrically, this is the best I can do. The player is guaranteed to exit at the correct position, though. --- src/k_kart.c | 9 +++++++++ src/p_loop.c | 10 +++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 8ea9d92ab..9635ad966 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -7847,6 +7847,15 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) player->mo->sprzoff += player->cameraOffset; } + if (player->loop.radius) + { + // Offset sprite Z position so wheels touch top of + // hitbox when rotated 180 degrees. + // TODO: this should be generalized for pitch/roll + angle_t pitch = FixedAngle(player->loop.revolution * 360) / 2; + player->mo->sprzoff += FixedMul(player->mo->height, FSIN(pitch)); + } + K_UpdateOffroad(player); K_UpdateDraft(player); K_UpdateEngineSounds(player); // Thanks, VAda! diff --git a/src/p_loop.c b/src/p_loop.c index 12ef3d714..b0aeb7a79 100644 --- a/src/p_loop.c +++ b/src/p_loop.c @@ -96,7 +96,7 @@ boolean P_PlayerOrbit(player_t *player) angle_t pitch; angle_t pitch_normal; - fixed_t xy, z; + fixed_t r, xy, z; fixed_t xs, ys; fixed_t step, th, left; @@ -124,9 +124,13 @@ boolean P_PlayerOrbit(player_t *player) pitch = get_pitch(s->revolution); pitch_normal = get_pitch(normal_revolution(s) / 2); + r = abs(s->radius) - + FixedMul(player->mo->radius, abs(FSIN(pitch))); - xy = FixedMul(abs(s->radius), FSIN(pitch)); - z = FixedMul(abs(s->radius), -(FCOS(pitch))); + xy = FixedMul(r, FSIN(pitch)); + + z = FixedMul(abs(s->radius), -(FCOS(pitch))) - + FixedMul(player->mo->height, FSIN(pitch / 2)); // XY shift is transformed on wave scale; less movement // at start and end of rotation, more halfway.