3D Physics example?

Hey folks, the Defold docs mention support for 3D physics, however I can’t find any examples of how to use these physics. Anyone have any tutorials / examples that walk through a basic use-case?

This example has some 3D physics https://github.com/subsoap/fps

Unfortunately there are still some problems with 3D physics in Defold

  • Sometimes 3D physics collision objects are placed differently in engine than they are in editor
  • In editor you can only see the 3D physics collision shapes as flat shapes
  • We can’t use meshes as collision shapes so making something like a racing game with varied terrain is not easily possible

There are still games you could make with these limitations although it would take extra trial and error. It might be better to make a mini level editor within the engine for your use case rather than to try to make it work with the Defold editor.

1 Like

@sven, you played around with a 3D racing game, didn’t you? How did you solve the physics?

I actually used 2D physics for that game, and faked height differences based on a height map. :slight_smile:

It looked like this;

As you probably can see the height and tilting is faked based on the car/objects position relative to the closest road.

13 Likes

Ship it!

6 Likes

I think if you sampled multiple points of the heightmap around where the vehicle was you would be able to use that for tilt.

Once we can use meshes for level collision geometry it will open up a lot of kinds of games that can be made reasonable easily. I think bullet physics can use height field for terrain too so the support for it in bullet is already there…

2 Likes

It does two samples currently, one for the front and one for the back, so it has some sort of tilting comparable to “pitch”. Should be able to add two more to get some sort of “roll”. :+1:

1 Like

Resurrecting an old post, but I thought Id add some notes to the conversation that might help others.
Rather than making a collision mesh for terrain (which is big an expensive to collide against) it is far easier and much faster to do a “height depth render” from a camera position above the vehicle (without the vehicle in the render). The depth render camera need only point down or mostly down :wink: … and you can make a very accurate collision lookup with a very low sample rendertexture for this.

Also, you can get the collision information on a wider area to a rendertexture then only update as you near the edge of it.
Hope this helps.

3 Likes

If you can share a sample project of those concepts it would be very welcome! :slight_smile:

I’ll knock something up once I get the physics for my vehicle doing the right thing :slight_smile:
I have a threejs webgl version using the same methodology and Im pretty sure Defold can do it too.
Probably a newton + vehicle + height lookup sample should end up in my samples repo :slight_smile:

4 Likes