Real Physics Enabled Racing Game

I have it working… Ill make a little video…

I need to talk to someone who has made a real physics car game about some of the mechanics…

For example… I am just making shit up about:

  • Motion
  • Turning
  • Skidding
  • Drifting (Faked)
  • Handbraking


To RE-CREATE what the Unity Wheel Colliders do for Unity Developers… And that is basically Expose the PhysX Vehicle SDK via the setting on the Wheel collider… I do the same thing except i use Bullet instead of PhysX… Remeber the goal for me (The Babylon Toolkit) is to make the TOOLING and SDK to get that Unity Like Experience when developing a babylon JS game…

I wanna talk to some folks so see… Hey… is that right or … Well the industry normally does it this way…
or something … Anything from anybody… I just wanna talk to another developer about racing games and how they do things

NOT USING PHYSICS kinda of defeats the whole point of creating a Racing Game (Unity Style… Editor, Scripts, Model Setup… etc) but for our Babylon JS games :slight_smile:

Ill show you what i got so far… ill make a quick video or something :slight_smile:

I’ve been trying to make a physics based racing game myself with ammo.js. I’ve had a similar problem with trying to drift the car causing the car to just roll over instead of sliding. See here for an example

This is my first attempt at this sort of thing and I have the same questions, so I’d be super curious to know what you find out.

Kool… I will take a look at your demo.

I am not only creating a racing game. But more creating the vehicle sdk and the track tooling used to make any kind racing game from car racing to mario kart style racing.

And most important… How i architected the game project using the Babylon Toolkit.

I made a video here:

But for some reason my screen recorder software is making a blurry video. It looks sweet on my screen as i am recording it but the final video is choppy and blurry. I am using the GoToMeeting screen recording software for Mac.

Side note: Does anybody know of a good screen recording software for Mac. Something i can use to make training videos and demo ???

@Wingnut … Check out the video… kinda choppy and blurry, but you can get the gist :slight_smile:

1 Like

@Deltakosh and @samuelgirardin and @trevordev … What can you throw in about making racing games…

Do any of you know about the how use the btTypeConstraint to handle proper friction slip using a Bullet Raycast Vehicle ???

Actually @bghgary, @trevordev, @PirateJC, @PatrickRyan, @Drigax, @syntheticmagus and @PolygonalSun worked on a pet project really closed to that:


Wow. I just crashed my browser before saving a project of mine ported to the PG. Only took a couple of hours :stuck_out_tongue:

Edit: Did a quick C/P of a smaller project:

I’m using the contact points of the front wheels to update a ribbon. This makes for some pretty decent tire tracks.

Have you tried tuning your rolling influence as well as your center of mass?


:smiley: i can imagine a rocket league with this one!

HUGE! I just limited the follow camera to not go underground:

This is really amazing! Good job!!

Very Nice @Deltakosh … I do alot of the same things with ammo native api.

Qusetion about the ribbons… I can put Tire Skid mark textures on the ribbon right ???

Also… How many seperate ribbons can you leave laying around on the ground… for example a race track… I see the ribbons disappears after a few seconds in demo. But i would like to emulate skidding and leave tire tracks on the ground for that skid… A new skid should make sepearte ribbon with tire texture and leave that on ground… Maybe start taking off after a long while or when the buffer of allowed skid marks has been reached.

Do you think i can handle that of of skid mark system using the ribbons ???

Yo @Deltakosh … can you do skidding or sliding… are you messing with the friction during the slide… I am having trouble implementing good sliding or skidding I to a turn… Can you help ???

@MackeyK24 would this work Use TrailMesh - Babylon.js Documentation ???

That looks very interesting… If i can create this trail mesh for each wheel as soon as the wheel skidding threshold is reached and then STOP trailing the wheel when skidding drops below threshold but LEAVE the trail mesh on the ground… (Until a timer makes them disappear or the track manager remove the skid mark because we reach max skid marks on track…)

Can the TrailMesh do that… (Please say yes)… I will take a look at the API as soon as i can. but those are my requirements for a skidmark :slight_smile:

EDIT: I dont know… i dont think that will work as is… I need to to create skid marks on the ground like in a need for speed style racing game. So its gotta create meshes on the ground (Some kind of dynamic mesh generation or something… If i can crate those ribbons with a SKIDMARK texture and leave on the ground when i i come out of that skid… that might work)

yup, that was just in case it would be of any help.

Thanks bro

Wow nice!
My local version uses a slightly altered version of BJS, so I can have like 10 different textures and a shit ton of effects using only one texture. I see that I’m using the wrong convex hull in the PG, so the impact sparks are… well… off :stuck_out_tongue:

Here’s a version with a dirt map:
(Give it a couple of minutes for the dirt to start, although it looks more… rusty)

It took me forever to convince the powers that be of Ammo.js to put in my fixes for Global Contact Support and how important Ammo.addFunction really is.

Im glad to see someone else using it:

var collisionCallbackPointer = Ammo.addFunction( collisionCallbackFunc);

Works like a charm dont it :slight_smile:

BTW… I have WASM builds of Ammo.js with all these fixes as well… Let me know if you want the Matching WASM builds for the Ammo.js from them Babylon Dist Folder

Yeah. AmmoJS is awesome, but hard to extend in JS, so any serious project should really be using their own fork. Take the RaycastVehicle. The default raycaster is missing collision masking/filtering, so you’ll have to either add a couple of lines in that function, or extend the class yourself.
My own version has a ton of added features. Anything from dynamic destruction to, well, most of the physics improvements in SuperTuxKart: GitHub - supertuxkart/stk-code: The code base of supertuxkart

But I get why it should be kept as simple as possible. My features are most likely useless to most people, so it would only add to (down)loading of the library.

Yo @Raggar … How are you using the Superkart code base in your ammo.js…

Did you make another ammo.js project and replace the WHOLE bullet folder ???

Did you just piece the changes from the superkart version into the ammo.js bullet 2.82 version ???

I am very interested in the Raycast Collision Filter code you used… Can you share that little peice with me :slight_smile:

I’ve taken the bit and parts and ported them over one by one. If I remember correctly, very few, if any, changes are needed to make it work.

In the castRay function of your raycaster, you simply put:

 rayCallback.m_collisionFilterMask = collisionFilterMask;
 rayCallback.m_collisionFilterGroup = collisionFilterGroup;

Before you do the rayTest.
So between setting the result callback and calling the rayTest function. Then it’s automatically handled.

Then you just need a way of setting your mask and group. The best way of doing this is to create a function that takes two ints, one for the mask and one for the group, and do collisionFilterMask = BIT(int)
Then export this function in the idl.

A cool feature of the SuperTuxKart project as well is auto-stabilization of the vehicle when airborne.
You can give it a Vector3 telling it which direction is up (0,1,0), and an int or float as an impulse to automatically stabilize the vehicle, so it hits the ground correctly.

        btVector3 kart_up    = getChassisWorldTransform().getBasis().getColumn(1);
        //btVector3 terrain_up = btVector3(0, 1, 0);
        // Length of axis depends on the angle - i.e. the further awat
        // the kart is from being upright, the larger the applied impulse
        // will be, resulting in fast changes when the kart is on its
        // side, but not overcompensating (and therefore shaking) when
        // the kart is not much away from being upright.
        btVector3 axis = kart_up.cross(terrain_up);

        // To avoid the kart going backwards/forwards (or rolling sideways),
        // set the pitch/roll to 0 before applying the 'straightening' impulse.
        // TODO: make this works if gravity is changed.
        btVector3 av = m_chassisBody->getAngularVelocity();
        // Give a nicely balanced feeling for rebalancing the kart
        m_chassisBody->applyTorqueImpulse(axis * stabImpulse);