Skip to content

Commit 50eed01

Browse files
committed
Merge pull request #101664 from drakeerv/master
Fix `get_rpm()` on wheel which has steering
2 parents 2e1803e + 6f25aee commit 50eed01

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

scene/3d/physics/vehicle_body_3d.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,18 +852,26 @@ void VehicleBody3D::_body_state_changed(PhysicsDirectBodyState3D *p_state) {
852852
for (int i = 0; i < wheels.size(); i++) {
853853
VehicleWheel3D &wheel = *wheels[i];
854854
Vector3 relpos = wheel.m_raycastInfo.m_hardPointWS - p_state->get_transform().origin;
855-
Vector3 vel = p_state->get_linear_velocity() + (p_state->get_angular_velocity()).cross(relpos); // * mPos);
855+
Vector3 vel = p_state->get_linear_velocity() + (p_state->get_angular_velocity()).cross(relpos);
856856

857857
if (wheel.m_raycastInfo.m_isInContact) {
858858
const Transform3D &chassisWorldTransform = p_state->get_transform();
859859

860+
// Get forward vector.
860861
Vector3 fwd(
861862
chassisWorldTransform.basis[0][Vector3::AXIS_Z],
862863
chassisWorldTransform.basis[1][Vector3::AXIS_Z],
863864
chassisWorldTransform.basis[2][Vector3::AXIS_Z]);
864865

866+
// Apply steering rotation to forward vector for steerable wheels.
867+
if (wheel.steers) {
868+
Basis steering_mat(Vector3(0, 1, 0), wheel.m_steering);
869+
fwd = steering_mat.xform(fwd);
870+
}
871+
865872
real_t proj = fwd.dot(wheel.m_raycastInfo.m_contactNormalWS);
866873
fwd -= wheel.m_raycastInfo.m_contactNormalWS * proj;
874+
fwd.normalize();
867875

868876
real_t proj2 = fwd.dot(vel);
869877

0 commit comments

Comments
 (0)