[SOLVED] Physics bounding box irregularities

Good evening all!

I am having some issues with my physic’s bounding box’s not lining up with their respective geometry. I’ve searched a bit and tried what few suggestions I’ve found (hard topic to search for!) but nothing’s worked. Please see below.


As you can see it’s random when they don’t line up, and they aren’t overlapping as I’ve made all boxes smaller but keeping them in the same spots and I still get the same results. Here is the code I use to create the geometry - minus the ground.

(brickLocationVector2fArray is a Vector2f List)

private static Node brickNode;
rootNode.attachChild(brickNode);
for (int i = 0; i < brickLocationVector2fArray.size() ; i++) {
Geometry brick_geo = new Geometry("brick", brick);
/** Attach material /
brick_geo.setMaterial(ground_mat);
/
* Move brick */
brick_geo.setLocalTranslation(brickLocationVector2fArray.get(i).getX(), brickLocationVector2fArray.get(i).getY(), 0.0f);
brick_phy = new RigidBodyControl(0.0f);
brick_geo.addControl(brick_phy);
brickNode.attachChild(brick_geo);
bulletAppState.getPhysicsSpace().add(brick_phy);
}

Please anyone let me know if you see something I can do to help, thanks!
talitore

Try attaching the spatial to the node before attaching the control to the spatial, this should make it easier for the automatic creation you invoke.

Normen,

Thanks for the quick response! I tried what you suggested and swapped code around to this and it’s still occurring.

for (int i = 0; i < brickLocationVector2fArray.size() ; i++) { Geometry brick_geo = new Geometry("brick", brick); brickNode.attachChild(brick_geo); /** Attach material */ brick_geo.setMaterial(ground_mat); /** Move brick */ brick_geo.setLocalTranslation(brickLocationVector2fArray.get(i).getX(), brickLocationVector2fArray.get(i).getY(), 0.0f); brick_phy = new RigidBodyControl(0.0f); brick_geo.addControl(brick_phy); bulletAppState.getPhysicsSpace().add(brick_phy); }

I think it has something to do with the bulletAppState. If I launch the app and rotate the camera around to render all of the boxes on screen, there will be zero errors. If I launch the app and immediately start moving via charControl.setWalkDirection(walkDirection); then there will be short stutters that I can see and the bounding boxes will be off again. I’ve been able to repeat this.

I know this is weird and probably confusing so please let me know what all information I can give to help.

talitore

Do you maybe accidentally change any of the built-in static variables, like Vector3f.UNIT_Y.multLocal(2); or so?

I don’t recall doing this and after searching I can’t find anything leading to that.

I went ahead and put the project up on github so anyone can take a look at it all. Be gentle though! It’s my first ‘real’ jMonkey app.

Thanks,
talitore

Try printing out Vector3f.ZERO, Vector3f.UNIT_Z etc. every frame. If they change somethings going wrong.

Hmm yeah, it looks like when I move Mario left/right then Vector3f.ZERO is changing values. No idea how I’m doing this, but I’ll investigate it and get back with you!

Thanks for the lead!
talitore

1 Like
@normen said: Try printing out Vector3f.ZERO, Vector3f.UNIT_Z etc. every frame. If they change somethings going wrong.

That was it! I changed walkDirection.addLocal(Vector3f.UNIT_X.mult(tpf * charRightSpeed * runSpeed)); to walkDirection = walkDirection.add(Vector3f.UNIT_X.mult(tpf * charRightSpeed * runSpeed)); and it corrected this issue. I must not understand addLocal. I thought it would have mutated walkDirection internally only, but it looks like it mutated the static also.

Anyways, hope this helps someone in the future!
talitore

1 Like

Most likely you have set walkDirection = Vector3f.UNIT_X at some point, so later modifying it also modified unitx. Initialize walkDirection as Vector3f.UNIT_X.clone;

1 Like

Maybe we should put an assert somewhere in the update loop to check these… Glad you solved your problem :slight_smile: