Bodies rotation around their axis

Link to my site:
Link to playground:

Hello. I want each wheel to rotate around its axis. It rotates around the common axis of the machine. What am I doing wrong? To start them, hold the spacebar.

Your PG does not work (CORS problems).

I think it’s a problem with the pivot point of your wheel meshes, they are not located where you want them to be for the rotation to work as expected.

See here for docs about pivot points: Set and Use a Pivot - Babylon.js Documentation

I tried to set the anchor points, but then the wheels spin around it. I need them to spin around their axis

This example shows one way of doing it Simple Car Following Path - Babylon.js Documentation.

They should do that.

Check the axis you are using. Are you spinning it around a local axis or a world axis.

See Using External Assets - Babylon.js Documentation to import your obj file
Thank you, I loaded the 3D model according to your instructions. Look please

I see you are using Making a Simple Driven Car - Babylon.js Documentation. To make full use of this I suggest you identify, in your project, the parts that make the carBody, and each individual wheel. Having done this follow the PG from the docs naming the carBody and wheels as in the PG. You will need to position the wheels according to your values. Use getAbsolutePosition() if needed.

Once you have identified the four wheels the other parts make up the car body. To identify the wheels use the Inspector to find node names. To get you started use this PG a simplified version of yours.



Setting the pivot point does work for me:

1 Like

Thank you very much). Really works. Could you help with one more small problem? When turning right, the machine goes back

It’s this line:

pivot.rotate(BABYLON.Axis.Y, phi, BABYLON.Space.WORLD);

If you set:

pivot.rotate(BABYLON.Axis.Y, -Math.abs(phi), BABYLON.Space.WORLD);

it will always go forward, but as I don’t really understand how all that is working, I’m not sure it is what you want…

To be honest, this line didn’t help me. The movement still doesn’t correspond to the buttons pressed

According to one of the picture in the doc pointed to by @JohnK, the main pivot should be on the right of the rear-right wheel, so in your case it is x=-50 and not x=+50:

See line 69.

I have commented out the rotation of the front wheels when the car is moving (lines 186-187 and 193-194): when uncommented, you will see it does not work as expected as soon as you use A/D and move forward.

I think it’s because you should not use setPivotPoint for the front wheels but instead create a dummy mesh as the pivot point and parent the wheel to this point (do it for each front wheel). That’s how it is done in the sample, and as it is working it must be the right way to do it.

1 Like