Hi all,
I’m struggling with making a staircase collidable. What I’m currently trying to accomplish is a CompoundCollisionShape made of 4 small BoxCollisionShape but I can’t for the life of me figure out why it simply doesn’t do anything on the scene. Here’s what I tried so far:
TRY #1 – 4 controls ARE created but on the scene I only see 1 or they’re all perfectly aligned so that I only see one, not sure but by going like this.node.getControl(0…3) != null I assume they’re all set because 4 returns null and 0…3 returns a control…
[java]
BoxCollisionShape cs1 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.2f));
RigidBodyControl rbc1 = new RigidBodyControl(cs1, 0);
rbc1.setPhysicsLocation(location.subtract(0, 0.3f, 0.3f));
rbc1.setPhysicsRotation(rotation);
this.node.addControl(rbc1);
BoxCollisionShape cs2 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.2f));
RigidBodyControl rbc2 = new RigidBodyControl(cs2, 0);
rbc2.setPhysicsLocation(location);
rbc2.setPhysicsRotation(rotation);
this.node.addControl(rbc2);
BoxCollisionShape cs3 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.2f));
RigidBodyControl rbc3 = new RigidBodyControl(cs3, 0);
rbc3.setPhysicsLocation(location.add(0, 0.3f, 0.3f));
rbc3.setPhysicsRotation(rotation);
this.node.addControl(rbc3);
BoxCollisionShape cs4 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.2f));
RigidBodyControl rbc4 = new RigidBodyControl(cs4, 0);
rbc4.setPhysicsLocation(location.add(0, 0.6f, 0.6f));
rbc4.setPhysicsRotation(rotation);
this.node.addControl(rbc4);
this.app.get_bullet_app_state().getPhysicsSpace().add(this.node);
[/java]
TRY #2 – Then I thought of several odd things like maybe the BoxCollisionShape has to be slightly different for it to work (I had this issue with the bounding volume box in my app and I fixed it by adding 0.00001f to an axis so that it’s slightly different and then collisions would happen as expected) and also I thought that maybe I had to addControl() before setPhysicsLocation() but none of those 2 things made it work properly.
[java]
BoxCollisionShape cs1 = new BoxCollisionShape(new Vector3f(0.31f, 0.2f, 1.11f));
RigidBodyControl rbc1 = new RigidBodyControl(cs1, 0);
this.node.addControl(rbc1);
rbc1.setPhysicsLocation(location.subtract(0, 0.3f, 0.3f));
rbc1.setPhysicsRotation(rotation);
BoxCollisionShape cs2 = new BoxCollisionShape(new Vector3f(0.32f, 0.2f, 1.11f));
RigidBodyControl rbc2 = new RigidBodyControl(cs2, 0);
this.node.addControl(rbc2);
rbc2.setPhysicsLocation(location);
rbc2.setPhysicsRotation(rotation);
BoxCollisionShape cs3 = new BoxCollisionShape(new Vector3f(0.33f, 0.2f, 1.11f));
RigidBodyControl rbc3 = new RigidBodyControl(cs3, 0);
this.node.addControl(rbc3);
rbc3.setPhysicsLocation(location.add(0, 0.3f, 0.3f));
rbc3.setPhysicsRotation(rotation);
BoxCollisionShape cs4 = new BoxCollisionShape(new Vector3f(0.33f, 0.2f, 1.11f));
RigidBodyControl rbc4 = new RigidBodyControl(cs4, 0);
this.node.addControl(rbc4);
rbc4.setPhysicsLocation(location.add(0, 0.6f, 0.6f));
rbc4.setPhysicsRotation(rotation);
this.app.get_bullet_app_state().getPhysicsSpace().add(this.node);
[/java]
TRY #3 – That’s when I realized it should probably have tried to go the CompoundCollisionShape route. So that’s what I did and I tried to copy one of the rare posts on this forum that talks about CompoundCollisionShape, I tried like this with a GhostControl first:
[java]
CompoundCollisionShape compoundShape = new CompoundCollisionShape();
BoxCollisionShape cs1 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.11f));
compoundShape.addChildShape(cs1, location.subtract(0, 0.3f, 0.3f));
BoxCollisionShape cs2 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.11f));
compoundShape.addChildShape(cs2, location);
BoxCollisionShape cs3 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.11f));
compoundShape.addChildShape(cs3, location.add(0, 0.3f, 0.3f));
BoxCollisionShape cs4 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.11f));
compoundShape.addChildShape(cs4, location.add(0, 0.6f, 0.6f));
GhostControl gc = new GhostControl(compoundShape);
this.node.addControl(gc);
this.app.get_bullet_app_state().getPhysicsSpace().add(this.node);
[/java]
TRY #4 – Then I tried with a RigidBodyControl (exact same code as above but instead of GhostControl it’s RigidBodyControl) instead. Didn’t work, In both cases, absolutely no control is shown on the scene when I wireframe it. Then I thought maybe instead of adding the NODE to the PhysicsSpace, maybe I should add the actual control directly like this:
[java]
CompoundCollisionShape compoundShape = new CompoundCollisionShape();
BoxCollisionShape cs1 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.11f));
compoundShape.addChildShape(cs1, location.subtract(0, 0.3f, 0.3f));
BoxCollisionShape cs2 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.11f));
compoundShape.addChildShape(cs2, location);
BoxCollisionShape cs3 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.11f));
compoundShape.addChildShape(cs3, location.add(0, 0.3f, 0.3f));
BoxCollisionShape cs4 = new BoxCollisionShape(new Vector3f(0.3f, 0.2f, 1.11f));
compoundShape.addChildShape(cs4, location.add(0, 0.3f, 0.3f));
RigidBodyControl rbc = new RigidBodyControl(compoundShape, 0);
this.node.addControl(rbc);
this.app.get_bullet_app_state().getPhysicsSpace().add(rbc);
[/java]
…didn’t work. No control shows up on the scene
I’m hoping somebody can enlighten me on the matter Thx for reading through!