Strategy for physics in large 3D world

I’m working on creating a 3D golf simulation game and am looking for some advice related to Babylon. I have read a lot of the posts related to large scene creation and dynamic tiles, but didn’t really find the details I was looking for.

A bit of background first;

  • I’m very familiar with online map platforms like Cesium, Bing/Google Maps…
  • I’m already able to create a great 3D golf course in Cesium JS with good performance, but cesium doesn’t have any physics engine. I have 3D terrain tiles, and GLB models.
  • An average course in my game covers 10 sq KM and has 1m resolution for terrain. I have about 50 models, many which are trees that are instanced with less than 10K instances needed for a full course usually. If I get a good solution working and am ambitious, that largest course I’d likely attempt would be about 40 sq km since that’s the largest one in real life: Mission Hills Golf Club - Wikipedia
  • I’ve been ramping up on blender and could probably

The lack of physics engine in Cesium is a blocker so I have been looking at alternatives, including building the whole thing in Babylon. I’m fairly certain the code I used to generate the course in Cesium is a small fraction of what it would take in Babylon, and there are a lot of other out of the box features there that make it a good starting point, but maybe not a long-term solution.

Before starting over from scratch with Babylon I was wondering about potentially integrating Babylon with cesium, purely for the physics aspect. My thinking is that at any given point in the game the player will have a limited area in which the ball could make it to, for simplicity lets say a rectangle that’s 100 meters wide and 400 meters long (in reality I could potentially use a cone shape to reduce the area further). I was thinking I could possibly use an offscreen canvas with Bablylon and generate that limited area. I could extract a grid of height points from Cesium’s terrain and load the same models. Then I could use a physics engine in babylon to fire the ball and play out the physics of collisions, and just translate the positions from the offscreen canvas to the relative location in Cesium. Does this sound like a reasonable approach?

Side note, I do know that a golf ball flight path is heavily influenced by its spin and likely not something that would be very accurately reproduced in most physics engine. I have however, wrote an algorithm that calculates an accurate flight path with speed and direction information at any point along it. I currently use this for a flat driving range part of my app and it is pretty accurate to reality. I was thinking I could reuse this “ideal” information and step through it with moveWithCollisions until the first collision, then hand it off to a physics engine to simulate.

This sounds like a solid plan. Are you looking to use the PhysicsShapeType.HEIGHTFIELD shape?

If you’re using Babylon’s V2 Physics, you may need to make sure you’re using PhysicsPrestepType.ACTION instead of TELEPORT. The underlying physics engine, Havok, allows you to specify a location to move your object to. You can choose whether the object should teleport to that location or if the object should move to that location after the next simulation step (which allows the object to have a velocity and push other objects).


Your post also reminds me of this cool X post on LOD physics.

1 Like

Depending on how you want to control the ball, you may need to use Physics V2 only for collision detection and keep dynamics computation on your side.

I was thinking I could reuse this “ideal” information and step through it with moveWithCollisions until the first collision, then hand it off to a physics engine to simulate.

Movewithcollisions is an old legacy collision detection system mainly used for camera. I would not use that.

In addition to raycast, you can try shape cast

https://doc.babylonjs.com/features/featuresDeepDive/physics/shapeCast

2 Likes

I was thinking about using Physics V2 as Havok looks awesome. I had came across moveWithCollisions in some other threads, good to know its not the recommended approach now. I was thinking about using ray casting to determine if anything is in front of the ball before the first impact, then handing it over to Havok. I hadn’t come across PhysicsShapeType.HEIGHTFIELD yet, so will look into it. Given that I’m in an experimental phase without any deadlines, I’m planning to trying a bunch of different things to see what provides the best performance. Thanks for the help!