Collision Detection

Hey guys,



I've been playing around with jME for about a month… It's my first 3D programing experiance and it's been fun.  The hard work you guys have put in so far is pretty awesome!  Hopefully I'll be able to contribute something someday… that'd be cool.



I'm having some problems with collisions… I've made a CollisionManager that is supposed to see if registered Collidables have collided, and if so it will perform a certain action.  I'm using the hasCollision() method of a Spatial (specifically a Node) witch contains the object I am interested like this:  object1.hasCollision(object2, true);



When the objects have not collided, there is no problem, but when they have I get a NullPointerException from TriMesh.hasCollision(); (obviously called via the recursion of hasCollision)… so, two questions… why do you think this happened, and is this the best way of detecting a collision between two KNOWN objects???



Thanks,

webaf409

As for the exception: please post a stacktrace with line numbers (build with debug info). And probably more info about your scenegraph setup.



If it's the best solution - one can always come up with something more specific of more things are known about your objects. But it's the default way in jME.

Another solution would be using jMEPhysics.

Stack Trace:



java.lang.NullPointerException

        at com.jme.scene.TriMesh.hasCollision(Unknown Source)

        at com.jme.scene.Node.hasCollision(Unknown Source)

        at mowermadness.collision.CollisionManager.getCollisions(Unknown Source)



        at mowermadness.collision.CollisionManager.update(Unknown Source)

        at mowermadness.app.CarTest.simpleUpdate(Unknown Source)

        at mowermadness.app.MowerGame.update(Unknown Source)

        at com.jme.app.BaseGame.start(Unknown Source)

        at mowermadness.app.CarTest.main(Unknown Source)



(no line numbers  ://)



Scene Graph Outline:

             


RootNode
              /                                 
      CarRoot1 (Node)              CarRoot2 (Node)
      /                                        /           
Chassis(Node)  Wheels          Chassis(Node)  Wheels
|            |                              |              |
Geom    CameraNodes            Geom        CameraNodes


Each Car is also a Car in the jME Physics Engine, thus the chassis/wheel separation.
I'm checking for a collision between the two CarRoot Nodes.

Allright, I got it solved!!!



I had a partical system attached to the car's root node… the one I used for collision detection.  Take that away and everything's good!  Something interesting I found:  when the car collided with a geom, and the collision was detected by the car (car.hasCollision(box, true):wink: the partical system was not an issue… however when called in the inverse form (box.hasCollision(car, true):wink: there was a problem.



Was this an expected problem given the partical system was there?