How to manually check colision [SOLVED]

Yes, thats it. I guess in the moment of the collision, he just remove the whole object and replace it by the peaces object… I dont know, I could do it, but I would like to test it doing in parts, changing the meshes, if I could find a fast way to do the collision calculations, it will be less objects in the scene.
I was planning to do a spaceship mining game, where the ship just shoot and explode asteroids in small peaces, since this ship can shoot multiple asteroids at the same time, it will fill the scene with geoms very fast…

For better understanding of the problem, imagine an space mining game scenario where the player needs to mine an very big rock shotting lasers on it.
When the lasers hit the rock, it will break a small part of the rock in some peaces, the player needs then to collect this peaces.
Now, if the rock is big, it will have thousands of peaces inside, if I put all this it in the scene it will be very performance consuming.
That is why I am looking to a way to do fast colisions check in memory.

A collision check is a collision check, it always happens in memory.

That is true. Maybe if I just create ghosts for this objects and create an control for the peaces it will fix my probem… Is the ghost approuch the fast way to do colision in jm3 ?

Just do what normen says. I have yet to see someone doing something else for what you want to do.
You are doing that with asteroids and I’m doing that with body parts… It’s the same.

Just replace your model by the model of its body parts and apply a force to them.

EDIT: Ohhh … maybe I understand you … You plan to make your asteroid broken pieces asteroid themselves ? So 1 asteroid could lead to 4 debri
s which could lead to 16 debris an so on, and you fear that it’s going to fill your scene graph ? Just reduce the number of broken pieces by some kind of inverse function of the size of the asteroid ! This way the small ones will stop making debris, breaking the chain reaction :slight_smile:

I think you might not be aware that ghost object collisions always happen with the bounding box of the ghost object. Just add the pieces with RigidBodies when the wall is supposed to explode.

I cant just replace it, imagine one big asteroid with 10000 peaces inside, if I just swap one geom to 10000 smalll geons it will break the scene. Dosent mather if they will be in collate state.

Will try that !

You won’t get anything near 10000 pieces anyway (note: if you didn’t see it in an AAA game yet its not because their programmers are too stupid). Make a few big pieces and do the rest with particle effects.

I saw a game doing this, and this game was done in Jmonkey I think. The game is Starmade, it use it to calculate and apply damage on the hull of the ships, it remove peaces from the ship when it get hited. Its voxel thought, it means its easy for the physical calculations since everything is a box, but still …
I will try the ghost+rigid body only approuch, lets see how much fps I will get…

All you need to do is :
(1) Listen to the collision between A and B (A being ONE asteroid and B being the laser for example)
(2) In you callback, when the collision happens, you just detach A from your scene graph
(3) Add again many A (but scaled down) to your scene where the collision happened.
(4) Apply a force to each A added at (3).

Note that adding 10 000 spatials to your scene graph will probably bring your computer on his knees. Is that really necessary ? 10 000 sounds like too much to me. I think if you really need those 10 000 parts you’ll have to find more creative ways … you probably don’t need them all at once in the scene graph.

Actually I was not planning to apply any force to all peaces, just on the ones close to the laser…

Nope, didnt worked, I got very poor performance when I did just this on the asteroid init :

        // Add Ghosts for all peaces
        for(int t=1; t<= asteroidParts.size()-1; t++) { // Obs not starting from 0, 0 is the whole object
            GhostControl asteroidPeaceGhostControl = new GhostControl(new HullCollisionShape( asteroidParts.get(t).getMesh() ));

Ideas ?

I’m not sure about that but couldn’t you use spherecollisionshapes ? I know asteroids are (often) spherical but that might be good enough for your needs.

But anyway … if asteroidParts.size() is too big you’ll always have performance problems. How long is it ? Start with 5-6 … not 10 000 :slight_smile:

EDIT: for that many pieces you might find some interesting things in gas / fluid simulation algorithms. But once again, I don’t think you really need that much.

So… this is just a ray intersection? That’s quite a bit simpler than body->body collisions.

It’s easier for everything since every mesh will be generated on the fly from the voxels. He’s not holding 10,000 cubes in memory waiting for them to be broken up… there is one object… then there is more than one object. That’s the way voxels work.

Also, I very much doubt physics is used for anything related to lasers.

Well, some numbers :

  1. Asteroid object whole num faces = 1538.
  2. Each peace num of faces (arround) = 20
  3. Num of peaces = 100
  4. Performance with 150 whole asteroids = 150 fps.
  5. Performance with only 1 group of spherical physical peaces = 10 fps.
  6. Performance with only 1 group of hullshape physical peaces = 0.5 fps.
    I tried just the hullshape and sherical, didnt tried boxes, but I dont think it will help much.
    I am lousing too much fps if using any time of ghost on this… With 150 asteroids I have arround 150 fps, with guost for each peace, cant get anyway to get bether fps then 10…

Using a bunch of ghost objects to do laser collisions is like trying to swat a fly with a bunch of big sledge hammers.

It could be just a ray intersection… But I would need to calculate an explosion area of effect anyway.
About Starmade, I saw it handling ships with 3 bilions box peaces. I think it was made with Jm3 because we can see the libs on the game dir.
But even using boxes, I could not get close to this performance…
I really think they are not using ghosts and just built an customized collision funcion, as it is just boxes its very easy to write one…

Head through the wall yet? Maybe you try to do what was suggested.

Just a video of starmade : StarMade #206 - Imperium Viking PvP ship [weapons demonstration] - YouTube
I think this ship has arround 500k blocks. Arround min 2:00 its more or less the effect I want.
I am thinking I could use boxes, since my “laser bullet” is an box and the peaces of the asteroid could also be boxes, but I could get an good performance with ghost anyway.