Simple Vehicle Wheel Physics

Hi all, I am very new to all this but ran out of resources to find a solution for my issue (including all the AI bots out there).

I am trying to build a simple wheel + vehicle mechanic and control. Movement is simply forward/backward/left/right.

I am able to steer the wheel left (testing with left only, will replicate a working solution to steer right), and i am able to return the wheel to its previous original position with the key to steer left is no longer pressed, but both the steer AND returning the wheel back exert a force that is big enough to move the whole vehicle. I tried different things; playing with mass, friction, etc. nothing worked.

here;s my playground https://playground.babylonjs.com/#OGA1OK

Am i doing this the wrong way? should I not try to steer using physics and try to change the rotation of the mesh and sync the physics body and pray things will work out?

2 Likes

Hey and welcome!

Let me summon our Physics overlord: @Cedric

Yo @qv1

Seems like alot of extra stuff… You should be able to accomplish the same thing with just a rigidbody and four raycasts for the wheels… Thats how most physics based driving games are made. For example Ammo.js uses btRaycastVehicle class. Here is an older Ammo.js I created before:

My Demo Racer Project

I need to publish my Havok Physics V2 based version… Just have not had the time to create
a demo playground for that one yet

4 Likes

And here is a video showing the city map and mustang car assets that I used with the Babylon Toolkit to create the demo racer project

2 Likes

Thank you for the reply. I didn’t know about the raycasting approach. I will try to read about it and see what I need to do.

Simulating physics is important for my project, is using traditional physics to simulate movement that unconventional?

1 Like

Sharing @Raggar 's Playground of a Havok raycast vehicle: Havok RaycastVehicle

3 Likes

Super cool, as always!!

Here’s a page I haven’t got to reading yet, though I think could be helpful here: Vehicles — physx 5.4.1 documentation

Thank you for the resource, very helpful - though a bit of an overkill for me. I don’t need suspensions and all that complex mechanics. I just need forward/backward/left/right movement, think of a warehouse robot kind of motion

a few examples:

There won’t be high speeds or drifting or racing in this at all.

Not sure if that changes anything but thought I’d share more about the use case.

1 Like

I love @Raggar’s PG
Documentation needs improvement to have, at least, a good intro to vehicles with Physics V2.

1 Like

Me 2 … I used @Raggar Havok Raycast Vehicle Physics as a guide to create my Havok Raycast Vehicle… I added a bunch of stuff I had in my custom ammo builds for high speed driving and smooth surface collisions.

My version is heavily modified to give you that fast paced and high speed need for speed style racing. But take a look at Ragger playground, its a great place to start

2 Likes

@qv1 @CrashMaster has also shared a Havok Car Playground that seems similar to the examples you shared

1 Like

I think you just track the pivots and constrain them maybe with an armature even. And just manually do the rest.

Ah thank you for that example from CrashMaster, it is trying to do what I am doing, I think I am further along in making it work though

I don’t think I am experienced enough to translate this into an actual method :smiley:

Your implemention looks better than mine indeed ^^ My stearing works more like a tank than a car by rotating the wheels in opposite directions, so that might not be what you want

1 Like

A small update. I am pretty satisfied with the forward/backward movement. Turning is still a problem

https://playground.babylonjs.com/#OGA1OK#1

@CrashMaster I loved your implementation, I couldn’t use it because 1) couldn’t turn while moving forward/backward and 2) need to visualize the wheels turning

4 Likes