PhysicsV2 Car Simulation Template

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

Awesome, thank you for sharing :smile:

1 Like

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

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).

2024-12-14-03-55-58-220

There is also a second version with a broken floor

PhysicsV2 Car Simulation Example (The broken floor)

Запись_2024_12_14_06_35_54_915 (1)

PhysicsV2 Car Simulation Example (Endless backrooms)

Maybe someone will continue my idea

6 Likes

Spiral race track - https://www.babylonjs-playground.com/#ANV5OM#123

4 Likes

the guardrail is a nice touch :laughing: I would keep falling without it

1 Like

Circular race track - https://www.babylonjs-playground.com/#ANV5OM#139
With speed meter and time counter.
The next step is to add some obstacles :slight_smile:

1 Like

Really useful thing

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!

Yes, now it has more sporty riding style :slight_smile:

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

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