From 11dbca74131e0034fcce320c6cf398dd40ec3737 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 8 Feb 2026 22:11:40 -0800 Subject: [PATCH] Fix character attachment to follow mount's full rotation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Character now properly rotates with the mount during flight instead of just bobbing up and down. This fixes the issue where the character appeared to float away from the mount during rolls and pitch changes. Implementation: - Create rotation matrix from mount's pitch, roll, yaw - Transform rider offset through rotation (local → world space) - Apply same rotation to character model (glued to mount) - Character stays properly seated during all mount movements Before: Character only offset vertically, sliding around during banking After: Character rotates with mount, stays firmly attached during all maneuvers --- src/rendering/renderer.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/rendering/renderer.cpp b/src/rendering/renderer.cpp index 67e2b7b8..da7d81c1 100644 --- a/src/rendering/renderer.cpp +++ b/src/rendering/renderer.cpp @@ -702,10 +702,28 @@ void Renderer::updateCharacterAnimation() { } } - // Offset player Z above mount + bob - glm::vec3 playerPos = characterPosition; - playerPos.z += mountHeightOffset_ + mountBob; + // Character follows mount's full rotation (pitch, roll, yaw) + // This keeps the character "glued" to the mount during banking/climbing + float yawRad = glm::radians(characterYaw); + + // Create rotation matrix from mount's orientation + glm::mat4 mountRotation = glm::mat4(1.0f); + mountRotation = glm::rotate(mountRotation, yawRad, glm::vec3(0.0f, 0.0f, 1.0f)); // Yaw (Z) + mountRotation = glm::rotate(mountRotation, mountRoll_, glm::vec3(1.0f, 0.0f, 0.0f)); // Roll (X) + mountRotation = glm::rotate(mountRotation, mountPitch_, glm::vec3(0.0f, 1.0f, 0.0f)); // Pitch (Y) + + // Offset in mount's local space (rider sits above mount) + glm::vec3 localOffset(0.0f, 0.0f, mountHeightOffset_ + mountBob); + + // Transform offset through mount's rotation to get world-space offset + glm::vec3 worldOffset = glm::vec3(mountRotation * glm::vec4(localOffset, 0.0f)); + + // Character position = mount position + rotated offset + glm::vec3 playerPos = characterPosition + worldOffset; characterRenderer->setInstancePosition(characterInstanceId, playerPos); + + // Character rotates with mount (same pitch, roll, yaw) + characterRenderer->setInstanceRotation(characterInstanceId, glm::vec3(mountPitch_, mountRoll_, yawRad)); return; }