I’m just looking for a general pointer on what to do: I’ve got a complex model (a spacestation) which has lots of gaps where a spaceship could fly through. If I just add a boundingbox, then a collision occurs as soon as a spaceship enters the station’s area. What’s the solution here so that a spaceship can fly through the gaps without registering a collision? Do I need to manually create lots of smaller bounding areas for each section of the station?
A mesh-accurate shape for static or kinematic Spatials. Can have complex shapes with openings and appendages.
Limitations: Collisions between two mesh-accurate
shapes cannot be detected, only non-mesh shapes can collide with this
shape. This Shape does not work with dynamic Spatials.
Limitations: CPU intensive, use sparingly! We recommend
using HullCollisionShape (or CompoundShape) instead to improve
performance. Collisions between two mesh-accurate shapes cannot be
detected, only non-mesh shapes can collide with this shape.
As you can see, there are some complications. Maybe someone else knows the complete answer.
Use a compoundCollisionShape for your ship or , if your use case permits it, a simple sphereShape, boxShape, etc.
Then, it will collide fine with a complex shape (space station).
You really only have 2 limitations:
complex shapes can’t collide together (nb: a compoundCollisionShape is not a “complex shape”)
performances should keep you away from GImpactCollisionShape for the station. In your case, I’d use a MeshCollisionShape for your station… you will be astonished by how performant and easy to use bullet is with jme. I’m still in awe lol.
I know the wiki says this, but it’s not true… gimpact vs meshshape works and i’m pretty sure that also gimpact vs gimpact works. The weird behaviour of the gimpact shapes was due a bug in the bullet native bindings that has been fixed in the master, so if you want to use them atm you should recompile the bullet bindings with the source available on github or use jbullet.
If you need a movable rigidbody for the station i suggest (as ali already did) to use vhacd.
Hi again, I’ve spent the best part of a month trying to get “complex” collisions to work and I’m still no closer. I’ve written the following bare-bones test code which creates two boxes which are overlapping and AFAIK does everything correctly, but no collisions are registered. Could someone tell me what I’m doing wrong?
I’ve got to the stage where I’m trying everything. I had a look at the JME source and saw these methods so I thought I’d try them. I couldn’t find any code anywhere on the net that showed how to do complex collisions but without using all the physics and character controls etc… I want to keep direct control of all the spatials, but somehow know when they have collided.
Are you planning a case where two spacestations can collide into each other? If not, then a static collider is the way to go. They provide dead accurate collisions with super good performance.
You can move them around normally without any problems like everything else, they just can’t collide with other static which shouldn’t be a problem if you keep different spacestations away from each other.
It works pretty damn well for me:
I once asked why this works so well even when you move the static colliders (which shouldn’t be possible), but apparently nobody has a clue.
Thanks again for everybody’s response. I think I’ve found the solution thanks to your help!
In my earlier code, it turns out that you need to give it a mass of 1.0, even though I’m not using any actual physics. However, I’m now using a CollisionShapeFactory.createMeshShape() and a createDynamicMeshShape for each of my objects, and attaching them to a GhostControl. Now I get full control of the Spatials, and when there’s a collision, my PhysicsCollisionListener gets fired. (BTW, I get NPE’s if both my objects are using createMeshShape()).
My only (minor) issue now is the fact that the collisions are fired outside the main game loop, but that just means a bit of code refactoring. Cheers!