Help with the collision detection

Started by Melssj5, December 20, 2004, 05:57:36 AM

Previous topic - Next topic

Melssj5

Hello, I was reviewing the demos I downloaded, but I am afraid I cant understand them at all nor how the collision detection is made, I am making a first person game, so I am moving the camera, I tried but the all what I could do was detecting just the 5% of the walls, I need an easy and simple example of detecting a collision using the camera, please.

I set the collision mode to collide with others and with it self on the level once it was all merged, and I used check camera collision when moving the camera. I dont know, Why only works with specific walls, and only a few times?

I someone can help me with any piece of code, please do it.

I am doing an awt applet.

Thanks.
Nada por ahora

EgonOlsen

Are you really using checkCameraCollision()? If so, you should better use checkCameraCollisionEllipsoid() instead. If it still doesn't work, maybe the scale of you scene is too large. Play around with Config.collideOffset in that case.

Melssj5

Quote from: "EgonOlsen"Are you really using checkCameraCollision()? If so, you should better use checkCameraCollisionEllipsoid() instead. If it still doesn't work, maybe the scale of you scene is too large. Play around with Config.collideOffset in that case.

I set the Config.collideOffset on 400 and worked, but, It doesnt work perfectly when walking back, only when walking to the front. May anyone help me explaining me how does the collision detection works,and maybe little pieces of code or something.

Its very difficult to understand the doc of the engine becausse my English is not very good.  :(

When I found a wall, it stops, after that I can move in any direction but in back, the 50% of times I cant move back after detecting a collision. Heres the code I used:

private void formKeyPressed(java.awt.event.KeyEvent evt) {
       // Add your handling code here:
       
       if (evt.getKeyChar()=='w') {
           if (theWorld.checkCameraCollision(1, 3)==false)
               camera.moveCamera (Camera.CAMERA_MOVEIN, 3);
       }
       if (evt.getKeyChar()=='s') {
           if (theWorld.checkCameraCollision(-1, 3)==false)
               camera.moveCamera (Camera.CAMERA_MOVEOUT, 3);
       }
       if (evt.getKeyChar()=='a')
           camera.rotateAxis(camera.getBack().getYAxis(), -0.065f);
       if (evt.getKeyChar()=='d')
           camera.rotateAxis(camera.getBack().getYAxis(), 0.065f);
       if (evt.getKeyChar()==' ')
           camera.moveCamera (Camera.CAMERA_MOVEUP,5);
       if (evt.getKeyChar () == 'z')
           camera.moveCamera (Camera.CAMERA_MOVEDOWN,5);
       
       repaint ();
   }
Nada por ahora

EgonOlsen

If you want to use that kind of collision detection for the camera, make sure that you use the CAMERA_XXX constants for both, moveCamera() and checkCameraCollision(). Currently, you are feeding a -1 into the checkCameraCollision() which isn't even a supported constant for this method. It should work, if you are using CAMERA_MOVEIN and _MOVEOUT instead of 1 and -1, but then again, you should really have a look at the checkCameraCollisionEllipsoid()-method, because it's much more powerfull then the ray-polygon-method you are using now.

Hope this helps.