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

Idle vehicles 'drift' backwards. #12

Open
jackkrol opened this issue Mar 5, 2023 · 2 comments
Open

Idle vehicles 'drift' backwards. #12

jackkrol opened this issue Mar 5, 2023 · 2 comments

Comments

@jackkrol
Copy link

jackkrol commented Mar 5, 2023

Even with the Sandbox scene, I found an idle vehicle on flat terrain will always roll backwards. I traced it to line 1114:

1114 Vector3 wsDownDirection = transform.TransformDirection(Vector3.down);

Changing wsDownDirection from local down direction to global seems to solve the issue:

1114 Vector3 wsDownDirection = Vector3.down;

I found even when the axle offset y is the same for both rear and front wheels, sometimes the car doesn't align perfectly on the ground, so wsDownDirection doesn't perfectly align with global down, so the car is 'pushed' slightly backward. Any consequences to using Vector3.down?

@SergeyMakeev
Copy link
Owner

I think that using Vector3.down might lead to a non-orthogonal basis and hence odd results.
The better way might be to "round" the down direction a bit to make it perfectly aligned and avoid floating point imprecision.

Something like that (not tested)

Vector3 dd = transform.TransformDirection(Vector3.down);
float mul = 1000.0;
wsDownDirection  = new Vector3(
           Mathf.Round(dd.x * mul) / mul),
           Mathf.Round(dd.y * mul) / mul),
           Mathf.Round(dd.z * mul) / mul));

@msklywenn
Copy link

msklywenn commented Jan 28, 2025

This is actually due to the demo car being unbalanced. The back suspensions being weaker and the center of mass not being centered makes the car be slightly slanted. Thus, the down direction is never directly down and the car rolls. (Putting the same suspension force on both axles and a 0.11 for Z in the center of mass makes the vehicle balanced, btw)

I think the proper fix is to take into account ground friction so that the wheels can't move if the driving force is too weak.

A quick workaround is to have the car constantly braking while at ~0km/h, but that doesn't solve the issue of the car sliding down when steady and sideways on a slope.

I believe slideVelocity should be computed with Vector3.ProjectOnPlane(wheelVelocity, c_up)

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

3 participants