File tree Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Expand file tree Collapse file tree 1 file changed +9
-1
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments