You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the file PhysicsSamples/Assets/12. Raycast Car/Scripts/VehicleMechanics.cs, there appears to be a logical error in the handling of wheel steering and rolling, specifically in the #region handle wheel steering and #region handle wheel rotation sections. The issue causes steering wheels to not roll correctly.
Expected Behavior:
When a wheel is used for steering, it should both steer (change yaw angle) and roll (rotate about its axle) correctly based on the vehicle's movement and steering input.
Actual Behavior:
The steering wheels do not roll correctly. The logic in the #region handle wheel rotation section does not properly account for the steering angle when updating the wheel's rotation, leading to incorrect or inconsistent rolling behavior.
Code Snippet:
#region handle wheel steering
{
// update yaw angle if wheel is used for steering
if (wheel.ValueRO.UsedForSteering != 0)
{
quaternion wRotation = quaternion.AxisAngle(ceUp, desiredSteeringAngle);
weRight = math.rotate(wRotation, weRight);
weForward = math.rotate(wRotation, weForward);
newLocalTransform.ValueRW.Rotation = quaternion.AxisAngle(math.up(), desiredSteeringAngle);
}
}
#endregion
float currentSpeedUp = math.dot(velocityAtWheel, weUp);
float currentSpeedForward = math.dot(velocityAtWheel, weForward);
float currentSpeedRight = math.dot(velocityAtWheel, weRight);
#region handle wheel rotation
{
// update rotation of graphical representation about axle
bool isDriven = driveEngaged && wheel.ValueRO.UsedForDriving != 0;
float weRotation = isDriven
? (driveDesiredSpeed / mechanics.wheelBase)
: (currentSpeedForward / mechanics.wheelBase);
weRotation = math.radians(weRotation);
newLocalTransform.ValueRW.Rotation = math.mul(localTransform.ValueRO.Rotation, quaternion.AxisAngle(new float3(1f, 0f, 0f), weRotation)); // TODO Should this use newLocalTransform to read from?
}
#endregion
The text was updated successfully, but these errors were encountered:
xdxttt
changed the title
Incorrect Wheel Rotation Handling in VehicleMechanics.cs
Incorrect Wheel Rotation Handling in VehicleMechanics.cs of PhysicsSamples/Assets/12. Raycast Car
Feb 10, 2025
In the file PhysicsSamples/Assets/12. Raycast Car/Scripts/VehicleMechanics.cs, there appears to be a logical error in the handling of wheel steering and rolling, specifically in the #region handle wheel steering and #region handle wheel rotation sections. The issue causes steering wheels to not roll correctly.
Expected Behavior:
When a wheel is used for steering, it should both steer (change yaw angle) and roll (rotate about its axle) correctly based on the vehicle's movement and steering input.
Actual Behavior:
The steering wheels do not roll correctly. The logic in the #region handle wheel rotation section does not properly account for the steering angle when updating the wheel's rotation, leading to incorrect or inconsistent rolling behavior.
Code Snippet:
The text was updated successfully, but these errors were encountered: