Lag frame rate while using collision detection

Thank kman! I just add updateCollisionTree() method after load model and it work now. I

've solved my collision detecion but i got new problem.After i loaded 2 models (.3ds) in my game: my character and the stadium

and using the hasCollision() method in update(). There will be find if my player stand outside the stadium(70-80fps) , but when i move my player near the stadium,my frame rate crash down(2-3 fps!!!):


if (Model.hasCollision(Castle,true)) Model.getLocalTranslation().z+=0.1f;


If i remove this from my code, the frame rate is normal(70-80fps). Anybody help me!!!!Thank you so much

I haven't used jme's collision detection but I don't think moving the player in the + z direction on any collision is a good idea.  Depending on where you collide you might be pushing your model further into the castle or whatever it is the model is hitting.





You might want to tell us where and how often this is being called.



-Mike

i push the model follow the z axis just to see if collision events happen or not, to make sure that collisions are detected correctly (when my character meet some object like walls…). I called it in my main game loop (and have to call in main game loop to check every movements of my character). May be because my models are too complex? I'll try a gain…

It's most probably because you have many spatials:

If you want effective collision detection you have to organize your scenegraph accordingly. If you have everything attached to the rootNode you will get really slow collision detection because the colliding spatial must be checked against each other spatial separately. Organize your scenegraph hierarchically by location (see bsp tree etc.) and you will get much better results.

You can take a look at TestSwarm and turn off scenegraph reorganization while running to compare the speed. As a quick shot you could use the simple organization methods from that test (CollisionTreeManager) but you will get even better results with an application specific hierarchical structure.