Tr909
September 27, 2024, 1:02pm
1
Hi All,
I’ve created a car simulation example with Havok/PhysicsV2 that I think would be a great starting point for anyone interested! It implements:
Motorised joints for powered wheels and steering
Stiffness and damping (spring) 6DoF joints for suspension
Effective use of mass and friction
This means it might also be helpful for anyone struggling with those aspects of PhysicsV2.
PhysicsV2 Car Simulation Example | Babylon.js Playground (babylonjs-playground.com)
Hope it helps!
TR
15 Likes
regna
September 27, 2024, 3:50pm
2
Awesome, thank you for sharing
1 Like
qv1
October 1, 2024, 12:36pm
3
This is absolutely amazing, thank you so much for sharing, I have been working on something like this for a while and couldn’t get it to work.
1 Like
Tr909
October 6, 2024, 3:40am
4
Thanks for the positive feedback! Here’s what it can look like with a nice car model dropped in and some dramatic lighting -
Driving Simulation with Babylon.js / Havok Physics (youtube.com)
7 Likes
I changed your code and now the carpet floor is generated procedurally indefinitely!
PhysicsV2 Car Simulation Example (Endless carpet)
You just need to copy it and put it in the place of your code - PhysicsV2 Car Simulation Example | Babylon.js Playground (babylonjs-playground.com) .
There is also a second version with a broken floor
PhysicsV2 Car Simulation Example (The broken floor)
PhysicsV2 Car Simulation Example (Endless backrooms)
Maybe someone will continue my idea
6 Likes
labris
April 15, 2025, 6:39am
6
4 Likes
the guardrail is a nice touch I would keep falling without it
1 Like
labris
April 15, 2025, 11:03pm
8
Circular race track - https://www.babylonjs-playground.com/#ANV5OM#139
With speed meter and time counter.
The next step is to add some obstacles
1 Like
Tr909
April 18, 2025, 9:02am
10
You’ve inspired me to tweak the physics to be a bit more fun and fast PhysicsV2 Car Simulation Example | Babylon.js Playground
Makes your track a lot more difficult though!
labris
April 18, 2025, 11:19pm
11
Yes, now it has more sporty riding style
If I wanted to change the initial position of the car, how would I do that? I’ve tried adding carFrame.position.x = carFrame.position.x + 1;
as the last line of CreateCar()
but that doesn’t seem to have any effect.
I’d like to try this out on some external models, which is why I’m looking to update the initial position.
I’ve been able to make this work by doing the following:
const initialPosition = new BABYLON.Vector3(0, 2, 0);
carFrame.position = new BABYLON.Vector3(0 + initialPosition.x, 0.3 + initialPosition.y, 0 + initialPosition.z);
And then the same for all the wheels and axles. I’ll try this out on an external model, but will then also look into how to set the initial rotation.
1 Like
Tr909
May 20, 2025, 10:49am
14
Hello, you have to set the disablePreStep property to false on each physics body before changing the cars position. Here is an updated playground with this implemented PhysicsV2 Car Simulation Example | Babylon.js Playground
Pressing “r” triggers the Reset() function which moves the car back to the start of the track.
3 Likes