How to get distances between meshes

if you do not have team already, i would suggest simplify project idea like you said.

But generally what you said is not hard to do, difference is that you will need set Gravity per CS, not per physics space, and to avoid float accuracy loss, you would need correctly manage this spaces. (have subNodes and update origin point, so close mesh do not loose accuracy, same about physics)

Im not sure what you mean by CS, but i have gravity, sort of working. things fall to the planet proper, but its slow as ass (as a benchmark, an empty scene runs at about 850 fps, massive planet and a simple apple runs at around 700, but gravity simulations between just those two drops fps to 150, and i know thats not gonna scale well to more than a couple planets, which is not ideal

a) this seems like a really LARGE drop for applying a force to an apple based on direction. Maybe how you are simulating gravity is wonky?

b) “FPS” is not a good measure of performance because the numbers are not linear. Comparing average frame time can be more useful as its linear and can be measured over just the parts of the frame that interest you (ie: you can take rendering and other external frame hits out of the equation).

you use physics right?

and its slow with collision with planet?

if its slow, it mean you have badly optimized Collision Shape(CS) used there.

Lets say for 2d Terrain, we dont use Mesh or Box Collision Shapes(CS). There is used special “HeightmapBasedCollisionShape”. You should use similar method, but 3d based one.

Also you should split and make one Physics Space per planet space i assume.

yes i use physics, but i failed to mention the slowness is from calculating gravity (which would be ideal) not from collisions. and as for collision shape, i used a hull shape with the planets mesh.

i also cant really use a heightmap, since the planets are actual spheroids (atleast not that ive figured out, how to get heightmap to translate to a spheroid)

One physics space per planet sounds good, but then how do i handle one flying from one planet to another?

and if i do split physics spaces to planets, then what shall i do for “open/empty space”? i can see if i get a certain distance away from a planet, to move the player to a sort of “universe” physics space, but what if i then want to, say, shoot something thats still in the planets physics space? i feel like there would be a lot of performance issues moving a lot of entities between physics spaces, not to mention some bugs , like, what if two objects collide on either of the spaces? like, say, an asteroid at the literal edge of a planets physics space getting hit by, say, a missile, still in “universe space”? they would not collide properly, instead colliding when the missile is added to the planets physics space, and at this point the missile could be inside the asteroid already, giving false collision data

This doesn’t really make sense to me. How are you calculating gravity?

Vector3f dir = planetCenter.subtract(objectCenter);
float distSq = dir.length();
Vector3f force = dir.normalize().mult(G * m1 * m2 / distSq);

then you make physics spaces each some distance, and if you shoot something from near space to other space, then you just switch space on edges(for certain CS). thats all :slight_smile: im too lazy to paint images again.

paul, im calculating gravity as normal, its the nested for loops that are slow

radek, so how do i handle collisions at the edges of two spaces?

dupplicate CS for both spaces on edge :slight_smile:

  1. CS go into edge → create dupplication of it in second space as a ghost CS - no spatial assigned(you can do it even before its in edge - some margin before the edge)
  2. the “spatial updater CS” should be one that will get collision(you can decide which one is “master”, ofc it will be one that first will get collision and after reset and check again until it go out of edge margin), otherwise i assume its not important.
  3. remove not needed CS when its not near edge

Paul can tell you more. he had done this as i know.

What nested for loops? I thought you said you only had two objects and it was slow?

I think maybe you need to have a different way to manage your physics objects but it’s hard to tell since we don’t know what you are doing now.

1 Like

To make gravity work (as the normal system doesn’t support multipoint gravity), I had to make a nested for loop to iterate all the bodies affected by gravity. In this case, only two objects, but still around O(n^2), which i consider pretty slow. As for what I’m doing now, it’s a bit all over the place, but my current plan is for the game to have realistic gravity (meaning any object over a certain mass exerts gravity).

Lately, I’ve been considering dropping the “Planets” ordeal and going with looping terrain (TerrainQuad) to get a “planet”-like feel, but I can’t find a way to loop terrain in this way (being at the “edge” of the map, looking past the “edge” at the other side of the map, if that makes sense). In physics is easy, just move everything to the other side when it gets to the edge, but this looks bad rendered, the edge of the map is empty black (no skybox), and it’s like walking through a black wall to the other side.
I also cannot seem to figure out tunnels. I know about adjustHeight, but my planets dont have that luxury (being geometries), and at that, I don’t think adjustHeight was meant for tunnels