From cc64c71428bc7dd0c63790ba130b2d70b6434413 Mon Sep 17 00:00:00 2001 From: betalars Date: Thu, 29 Feb 2024 23:18:45 +0100 Subject: [PATCH] fix suspension length miscalculation --- scene/3d/physics/vehicle_body_3d.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scene/3d/physics/vehicle_body_3d.cpp b/scene/3d/physics/vehicle_body_3d.cpp index c23032d3b902..38e5b7acfba4 100644 --- a/scene/3d/physics/vehicle_body_3d.cpp +++ b/scene/3d/physics/vehicle_body_3d.cpp @@ -398,7 +398,6 @@ real_t VehicleBody3D::_ray_cast(int p_idx, PhysicsDirectBodyState3D *s) { Vector3 source = wheel.m_raycastInfo.m_hardPointWS; wheel.m_raycastInfo.m_contactPointWS = source + rayvector; const Vector3 &target = wheel.m_raycastInfo.m_contactPointWS; - source -= wheel.m_wheelRadius * wheel.m_raycastInfo.m_wheelDirectionWS; real_t param = real_t(0.); @@ -425,8 +424,7 @@ real_t VehicleBody3D::_ray_cast(int p_idx, PhysicsDirectBodyState3D *s) { wheel.m_raycastInfo.m_groundObject = Object::cast_to(rr.collider); } - real_t hitDistance = param * raylen; - wheel.m_raycastInfo.m_suspensionLength = hitDistance - wheel.m_wheelRadius; + wheel.m_raycastInfo.m_suspensionLength = source.distance_to(rr.position) - wheel.m_wheelRadius; //clamp on max suspension travel real_t minSuspensionLength = wheel.m_suspensionRestLength - wheel.m_maxSuspensionTravel;