Author Topic: Help with the collision detection  (Read 4734 times)

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Help with the collision detection
« on: December 20, 2004, 05:57:36 am »
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Help with the collision detection
« Reply #1 on: December 20, 2004, 07:47:17 pm »
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.

Offline Melssj5

  • double
  • *****
  • Posts: 724
    • View Profile
Again
« Reply #2 on: December 26, 2004, 02:17:00 am »
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:
Code: [Select]

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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Help with the collision detection
« Reply #3 on: December 26, 2004, 12:40:37 pm »
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.