Oddities in Collision Detection (Sorry to bug you again DP)

The new jar you gave me fixed the problem with regards to PhysicsObjects syncing with dynamic Geometry.

However, I have a new problem. I have my ship and I have a box. I just want basic regular old collision detection between the two. Unfortunately the ship is able to fly through about half the box before it collides with anything. From the other direction the ship collides with nothing. It’s almost as though the physical box used for collision detection is shifted a little to the left. Here’s the relavant code.

    protected void simpleInitGame() {
      //Create PhysicsWorld
      //Set up the PhysicsWorld. It's set with default values, e.g. Earths
      // gravity.
      PhysicsWorld.getInstance().setGravity(new Vector3f(0,0,0));
      // Here we tell the PhysicsWorld how many times per second we would like to
      // update it. It'll make the PhysicsWorlds internal timer govern the frequency
      // of update calls, thus obtaining frame rate independance. We set it to
      // 100 updates per second - the default is no restriction.
      // Here we tell the PhysicsWorld how much should change with each update.
      // A bigger value = faster animation. A step size of 2/UPS (updates/sec)
      // seem to give a rather nice simulation/result.
      //Create our Geometry
      //ShipModel simply extends TriMesh
      ShipModel ship = new ShipModel("My Ship");
      //Since ship is a trimesh it needs a bounding volume (or at least it complains when I don't have it)
       ship.setModelBound(new BoundingBox());
      Box box = new Box("box",new Vector3f(0,-2,0),new Vector3f(4,4,4));    // Make a box
      box.setLocalTranslation(new Vector3f(-10,0,0));
      // Create our Physics Objects
      shipObj = new PhysicsObject(ship, 50f);
      PhysicsObject boxObj = new PhysicsObject(box);
      // Add the graphical representations to the rootNode. You can also get
      // a reference to it by calling PhysicsObject.getjMEGeometry().
      // And the physical representations to the PhysicsWorld.
      //Pass a reference to the ship to the input handlers so they can manipulate the geometry and forces

Once again thank you for all your help. By the way, when the ship hit the box it spun all around in circles and everything. It was awesome to look at hehe.

it seems that the PhysicsWorld isn’t initing the Box correctly. Its making it smaller than it actually is.

Ive just ran a test with your arguments, and i can see whats going on. We aren’t calculating the extents of the box correctly.

I’l have to go through some code before I can give you a fix for this. But in the mean time, if you were to change the vector3f inside the box’s constructor from

new Vector3f(0, -2, 0);


new Vector3f(0, 0, 0);

That works fine.

And no, no one in the world can ever bug me. I am unbuggable! hehee

Oh yer, thanks for pointing out the bug…as i said, we need ya to get this working properly!


Ok, fixed! :smiley:

grab the new jar here

The problem was the centre of the box as i stated before. We were only calculating the lenghts of the box from its extents and forgetting about the centre.

So now, the position of the box is moved (during initing only) by its localTranslation as well as adding on its centre (in this case, we’re adding a negative number).

And thats fixed!


Fixed it is!! Thank you again!!

I’ll be continuing to work on this today … it’s looking great so far.

Hey shochu I have a question. How do you load your model as a TriMesh

It’s not a real “model” like an obj or jme model. I just made it by hand by extending the trimesh class so I don’t actually load anything.