# When turning the car, the wheels begin to rotate in the wrong direction

If you start the machine left and right, sooner or later the rotation of the wheels will break. How can this be solved?

UP: I noticed that during the rotation, the value of y changes, although I didn’t indicate it anywhere

Very interesting demo

I noticed you don’t actually use a physics engine for that, but kind’s built your own thing. Unless I am missing something - any reason you choose to implement motor and joint physics on your own?

To answer your direct question - The local axes of the wheel change when you rotate it constantly. I think the rotation axes should be calculated according to the car’s current state, and that you should add joint-elements to do the actual wheel rotation. So - either calculate current rotation in world space for each frame, or connect an object to rotate, and to it connect the wheel, which will preserve its local axes.

I don’t have a working example (and I am sure someone from the community will do a far better job than me), and this is, of course, just a suggestion

as for your question about physics. I just don’t know how to do this

I followed this example https://doc.babylonjs.com/snippets/car_driven

but I had to change the axes in the functions, because with the same code as in the example, it didn’t work

Although I still don’t understand what coincidence with the axes depends on. I just switched axes until at least something worked

When you load the car its orientation is not the same as the one in the snippet example https://www.babylonjs-playground.com/#AYD85K#27 (if car does not load then just run the PG again).

If you just use rotation to get it into the same orientation as the example then the axes for your car and the example car will not match.

To get them to match you must bake the transformations into the car https://www.babylonjs-playground.com/#AYD85K#26

Not entirely sure whether baking after parent will be enough, you can bake before parenting https://www.babylonjs-playground.com/#AYD85K#28 and see which (if not both) works best.

As well as removing the chassis from the parenting process you would need to remove wheel and wheel parts as well to keep them separate.

I have included a point and click routine to help you find the names of particular parts.

3 Likes

Thank you very much for a good example with axes. I tried to turn the machine according to an example, changed all the axes in the rotations, but the wheels still spin incorrectly

@11116 Not quite as simple as aligning your car with the snippet car as I thought. Here is your car aligned with the snippet car https://www.babylonjs-playground.com/#102TBD#173 wheels now rotate correctly.

Note line 104 since wheel is imported already vertical this is not necessary and lines 248 to 258 axis Y replaced with Z for same reason. The problem of the imported wheel is setting up its center correctly, I used a transformation of y = 4.11 but it is off a little which is noticeable as you turn the wheels.

You can see in this PG https://www.babylonjs-playground.com/#102TBD#176 where I made the wheels and so have control over the sizing and the center this is not an issue.

Obviously there is a difference in speed between you car and the snippet car because of scaling.

Hopefully you can work on sorting out these issues.

2 Likes