Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Wheel Rotation Handling in VehicleMechanics.cs of PhysicsSamples/Assets/12. Raycast Car #296

Open
xdxttt opened this issue Feb 10, 2025 · 0 comments

Comments

@xdxttt
Copy link

xdxttt commented 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:



#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
@xdxttt 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant