An implementation of a simple Raycast Vehicle using V2 physics.
I did a bit of experimental prediction when the vehicle is airborne, in order to soften and straighten the landing. I would like this feature to work while maintaining the original angular velocity, but haven’t figured out how to do it properly. All in all I think it handles decently, but there are certainly some areas in which it could be improved. The goal was some stable-ish driving when handling uneven terrain and some countermeasures to prevent it from rolling over during sharp turns. This sacrificed the natural rotation of the vehicle, but this could easily be artificially added using the applied side force

Live test
https://raggardk.github.io/

Repo

And a simplified Playground

13 Likes

So cool!!

1 Like

This is fun. I managed to lose my right front wheel which was… interesting.

It seems like there could be a threshold for “reasonable” right-side-up behavior, after which the physics give up and say “nope, you are in fact going to roll.” since the right-side-up restraints only kick in when you’re close to the ground (like you can spin upside down when the car is way up in the air), it would be interesting to play with a “bounce” vector. Simulating pent-up energy that releases. So that if you pass the “tilt” threshold, not only does the car roll, it also launches into the air for more spectacular gymnastics.

Anyway. Very nice work.

3 Likes

Also, I managed to get my car sandwiched under the ramp, and then it wouldn’t move. In terms of reasonable physics, that’s good!

very nice

1 Like

Awesome! , I managed to do a barrel roll of the ramp and again I did one once after ramping the base cone of one of the pillars

There is an odd sensation of acceleration when turning hard? Not sure if it is just perception based on the type of textures on the collision geometry

That wheel is the original imported model. I simply forgot to hide it when I created the four instances used as wheel meshes
I think the sandwiching happens in any physics engine. The engine is fighting between resolving the collision with the ground and the ramp
The center of mass is slightly lowered artificially, but you could zero it out when airborne to get more natural looking spinning

Edit: Center of mass setting and reduced prediction frames: https://playground.babylonjs.com/#8WQIA8#1
Seems to handle airborne spinning better

Not something I’ve felt personally, but I guess everything is possible

A test applying forces in various positions relative to the car’s center of mass:

More natural yaw and pitch, as you can see by quickly going forwards and backwards, as well as giving it a chance to roll over while grounded. Looks kinda funky, though

Something I was struggling with using ammo and cannon raycast vehicle was driving on non static body. You couldnt really do it with ammo but managed to do it with cannon. The use-case for me was taking off/landing a plane with wheels on an aircraft carrier.
Any idea if it would work with your implementation?

Unfortunately, you’ll get this effect:

This will happen with most implementation.
I did a quick test, but didn’t quite get it to work correctly, so it will require a bit of thinking
When your wheel(raycast) hits the kinematic body, take the velocity of the body and either apply that to your own velocity, or use it as an impulse. This worked perfectly fine for staying on the platform while it went forwards and backward. The issue I saw was with the side force. If I turn the car, it resolves the sideways forces, resulting in more or less ignoring the velocity it gets from the platform

Thanks for making effort in checking this.
It works fine in Cannon and I dont think I made any workarounds. I have to double check. You can chack their raycast vehicle implementation on their repo.

Yeah. Seems like Cannon handles this easily
I tried the code from Cannon. It glues to the platform sideways, but for/backwards not so much. I won’t have time to really work on it, but I’ll have it in mind for the future.
I’m not planning on added too much to this. If a proper simulation is needed, you’re better off using a proper implementation. This was more of a fun-project, and an improvement over my last vehicle physics

Its great as it is! There will always be some corner cases.

Super cool! I actually like that the car “rights” itself, I can drive around as much as I want while crashing into everything and launching from all the ramps

2 Likes

That’s really cool, I’ve done a lot of similar things lately but felt unsatisfied until I saw this

1 Like