Ye Olde 'Hollow' CollisionShape / Model

Hi folks,

I’m building a space sim, where the player controls a humanoid avatar. This avatar would be inside a spaceship. The spaceship would have some kind of control panel which the player avatar would interact with to move the vessel and its contents. Everything (ideally) would move according to some kind of realistic/newtonian physics.

So far I’ve accomplished the loading of two seperate .obj models - a spaceship and a humanoid. They both have DynamicMeshShapes and are both completely solid as far as collisions and physics are concerned.

I’ve read a number of posts regarding this matter and have decided that the only way I can easily accomplish what I want is to build the spaceship ‘walls’ out of different spatials, and attach them all to a single ‘spaceship’ node. I assume this is the only way to get this done whilst keeping a physical presence on both spaceship and avatar.

The problem is that I end up with 6 ‘walls’ for each ‘room’ of the spaceship. If I want multiple ships / stations in the game and/or more that one room per ship, that is going to add up to a lot of ‘physical’ spatials. Plus, I will no longer be able to build a spaceship model in Blender and import it.

I really don’t know where to go from here! Is there any way to tell JME that a model is hollow? Or do I scrap loading models and go with a set of spatials instead? Maybe I can somehow access each ‘wall’ inside my model and add it to the PhysicsSpace instead of the entire model?

Thanks
Dave

Addition - I’m reading about CompoundCollisionShapes and I’m thinking maybe I can create one of those from each of the meshes in my model, instead of using a single CollisionShape for the entire model?

i suggest to split logic

one physicspace for hulls andships, one for inside of ship, with a static mesh shape

1 Like

Just don’t make everything in one physics space. Have two, one for the room that the ship moves in and one for the people inside the ship. This way you can make the walls of the ship static and use a mesh collision shape which is hollow.

1 Like

Ah, so to clarify you’re saying I can have two distinct collisionShapes, one for each Physics space, applied to the same object? That’s very useful!

If I were to use a ‘normal’ CollisionMesh for the ship Physics space walls as you suggest, would they be able to rotate / translate accordingly with the ‘external’ DynColShape? I.e if the DynColShape is moving or rotating along with the actual ship model, am I able to set the same translation / rotation on the ‘interior’ walls? I think I read somewhere that they can’t be moved, but maybe its all relative.

Thanks for the info so far!
Dave

Physics and scenegraph are completely separate.

Of course. I am indeed finding it difficult to seperate the two in my head :stuck_out_tongue:

I wonder if this appertains to a similar problem Im dealing with - a donut shaped model. My intention is to have my ship be able to fly through the donut but at the moment the donut collision mesh is completely solid. I don’t think a seperate Physics space would fix the issue in this case but I bow to your wisdom.

Thanks

Right, I figured out how to use GImpact collision shapes - it works at the moment; maybe if I limit my solar system to 4 - 5 complex objects each, itll be fine.

For anyone looking to create a GImpact collision shape (I couldn’t find a specific example myself):

[java]Geometry geom = (Geometry) spatial;
GImpactCollisionShape collisionShape = new GImpactCollisionShape(geom.getMesh());[/java]

I can happily report that using GImpact collision shapes also allows collisions within the ‘interior’ of another shape. Performance doesn’t seem to be an issue at the moment, but there are only three ‘physical’ objects in my scene right now.

Thanks for all the help folks. Hope my findings can help someone someday!

@whoshotdk said: Of course. I am indeed finding it difficult to seperate the two in my head :P

I wonder if this appertains to a similar problem Im dealing with - a donut shaped model. My intention is to have my ship be able to fly through the donut but at the moment the donut collision mesh is completely solid. I don’t think a seperate Physics space would fix the issue in this case but I bow to your wisdom.

Thanks

@whoshotdk said: I can happily report that using GImpact collision shapes also allows collisions within the 'interior' of another shape. Performance doesn't seem to be an issue at the moment, but there are only three 'physical' objects in my scene right now.

Thanks for all the help folks. Hope my findings can help someone someday!

Yes my proposed solution can be used to make your ship bounce off stuff in the “space” (physics space 1) and at the same time coordinate the people in your ship, just set the physics controls for that physics space to “apply local”, then the objects will move along with the ship node. Its still two separate physics spaces then. If the ship collides with something thats space 1, if the people inside run into a wall thats space 2.

Also GImpact shapes are really very computation intense, maybe you are lucky with your current collision amount but I’d try to not use them.

Ok,

After a couple of days reading to re-inforce a few concepts in my head, I think I’m ready to ask another question regarding this solution. You both mention I should use a Mesh collision shape for the interior of my ship rather than a GImpact shape and that I should add my avatar to the ship’s physics space.

This sound good and I have already added the control system to enable entry/exit of the avatar in/out of the ship. If I keep the avatar in the ‘world’ physics space, the avatar can be placed inside the ship (for now simply using setPhysicslocation), no problem. Of course the ship / avatar still move independent of each other.

However, if I modify the code to add the avatar to the ship physics state when entering, the collision shape of the ship appears to become ‘solid’ again, the avatar position gets set to the ship but then immediately the avatar gets ‘spat out’ at speed when attempting to place him in the ship - im guessing a collision is happening.

I realise that a Mesh collision shape is hollow and also faster than GImpact shapes. So I imagine that this collision issue would not be an problem if I were able to use a Mesh collision shape instead of a GImpact or Dynamic one.

However, its not possible to create a rigidbody control from a mesh collision shape (?).

So I’m thinking I probably need to create my own simple box collision shape and use that instead of one generated from the model mesh itself. On every loop update, I would need to make sure the box collision shape was rotated/translated to the exact same position/rotation/scale of the ship room.

Am I getting this totally wrong again or is this vaguely along the right lines? Im starting to think I need to pay for some tuition for a few hours :stuck_out_tongue:

Thanks
Dave

1 Like

@Normen: the code I used to get the avatar in/out of the ship is based on pseudo code written by yourself last year, here:

http://hub.jmonkeyengine.org/forum/topic/creating-a-player-node/page/2/

You’ve been quite a helpful resource alone, actually :stuck_out_tongue:

The code I wrote, based on that:

[java]//Enter:
worldPhysicsState.getPhysicsSpace().remove(avatar.getRigidBody());
avatar.getRigidBody().setApplyPhysicsLocal(true);
avatar.rigidBody().setPhysicsLocation(ship.getPhysicsLocation());
ship.getNode().attachChild(avatar.getNode());
ship.getPhysicsState().getPhysicsSpace().add(avatar.getRigidBody());

//Exit:
ship.getPhysicsState().getPhysicsSpace().remove(avatar.getRigidBody());
avatar.getRigidBody().setApplyPhysicsLocal(false);
avatar.getRigidBody().setPhysicsLocation(avatar.getRigidBody().getPhysicsLocation().add(Vector3f.UNIT_X).mult(2));
rootNode.attachChild(avatar.getNode());
worldPhysicsState.getPhysicsSpace().add(avatar.getRigidBody());[/java]

You are getting it wrong, the physics spaces would have nothing to do with one another. There can’t be any collision happening between the ship hull (world space) and the player which is supposed to be in the ships interior physics space which would be local to the ship node. So also it would move along with it.

I must be missing something fundamental. I thought the code I pasted was already properly putting the avatar into the ship PhysicsSpace. Could you confirm that I did that bit correctly? I’m working on a lot of assumptions I know, but how it is / how I see it right now:

> The world has its own seperate BulletAppState, and the ship also has its own BulletAppState.
> The player avatar and ship start out within the World BulletAppState physicsSpace.
> When the player avatar enters a ship, its RigidBody is being added to the ships BulletAppState PhysicsSpace. Its scene node is also being attached as a child of the ships scene node.
> But…for some reason an ‘impossible’ collision occurs between the avatar’s collisionMesh and the ship’s collisionMesh - this only happens once the player avatar RB is attached to the ship’s PhysicsSpace. If i keep the avatar RB in the World PhysicsSpace instead, the collisions happen properly (the ship is hollow and only the walls cause a collision).

I actually don’t know why there is a different collision result here - but I am working on the assumption that I should not be using a GImpact collisionmesh once the player RB is inside the ship physics space. (i know i probably shouldnt use gImpacts at all, and if i get this working right i probably wont).

You say there should be no collision between interior player and ship hull in world space. I think I get that in principle. But, the ship collision boundaries don’t change shape - regardless of whether the player is in or out, the ship needs that same collision boundary - essentially a hollow box. Also regardless of in or out, the ship needs total physical control, as does the player (the player can move around within the ship whilst being part of its inertial frame of reference and affected by its forces).

I’d like to make it clear that when the player is within the ship, the player RB is attached to the ship BulletAppState PhysicsSpace and the ship RB is attached to the World BulletAppState Physics Space. IMHO that accomplishes: “the physics spaces would have nothing to do with one another”.

Obviously I’m wrong, as it doesn’t work as expected :smiley:

Its almost right, just that you have to use a separate, different collision shape in the world space for that ship, best a hull shape. Because a mesh shape cannot be dynamic (moving). Maybe I get around to making a little test case to exemplify this as many people seem to struggle with the concept of local physics spaces.

I’ve been a bit foolish, after more testing I discovered that I’m not getting an ‘impossible’ collision. I’d simply forgotten to set the local ship physics space gravity to zero, so the avatar was falling once they had been added to it.

The problem is now twofold:

There is seemingly no collision happening at all between player and ship, once player is inside the ship’s physics space.
If i set ship gravity to zero (to avoid falling out for now), then ‘enter’ the ship, then move the ship, the player does not ‘move along with’ the ship as i expected.


To start with, both player and ship RB’s are in same world physics space. On entry, the player RB gets removed from world physics space and added to ships physics space. I can sort of ‘get’ why the two RigidBodies no longer collide with one another now - they are in different physics spaces. But I need them to collide and as the player is now a child of the ship (in both spatial and physical terms) i would have thought it would move along with the ship when the ship moves.

I may be barking up the same wrong tree, but it looks like the ship needs an additional collisionMesh for itself attached to its own phsics space. Then it would be in the same physics space as the player now is, and they would collide correctly.

Is that approaching anywhere near correct?
Thanks for your patience

Actually, it looks like collision is happening but its all a bit jittery. If i move the player slowly enough into a ship wall, he will stop. but if i go faster i can force him through the wall. This jitter does not happen when both player and ship are in the world physics space though. It only happens when the player is in the ship physics space.

@whoshotdk said: Actually, it looks like collision is happening but its all a bit jittery. If i move the player slowly enough into a ship wall, he will stop. but if i go faster i can force him through the wall. This jitter does not happen when both player and ship are in the world physics space though. It only happens when the player is in the ship physics space.

Are both local? I mean maybe you see the objects in some place but in fact they collide elsewhere… The nightly debug view would show this (though nightly is very unstable else!).

No, the ship always remains in ‘World’ BulletAppState PhysicsSpace.

The avatar is moved from the ‘World’ BulletAppState PhysicsSpace to the ship’s own BulletAppState PhysicsSpace on entry to the ship. At the same time, its scene node is added as a child of the ship scene node.

Yeah, and the ship hull mesh shape is local in that ship physics space? Anyway I’ll see that I’ll hobble up an example test file for this.