Whats wrong with my collision detection

Started by Melssj5, September 04, 2005, 03:24:53 AM

Previous topic - Next topic

Melssj5

Hi, I have not used the engine in ages, so 2 days ago I began to do little project, but I just cant do the collision detection.

When I thought that it was good, I noticed that it didnt worked on the corners, I tried with other ways, but now the camera moves very quickly and no matter the speed I set.

here is my code for managing the events taken from the KeyState


public void movimientos () {
       
       boolean piso=false;
       try {
           if (Mundo.checkCameraCollision (new SimpleVector (0, 1, 0), alturaPersonal, alturaPersonal, false))
               piso=true;

           if (adelante)
               if (Mundo.checkCameraCollision (camaraPersonal.getDirection (), alturaPersonal, alturaPersonal, true))
                   camaraPersonal.moveCamera (Camera.CAMERA_MOVEIN, velocidadPersonal);

           if (atras)
               if (Mundo.checkCameraCollision (camaraPersonal.getDirection (), alturaPersonal, alturaPersonal, true))
                   camaraPersonal.moveCamera (Camera.CAMERA_MOVEOUT, velocidadPersonal);
           
           if (izquierda) camaraPersonal.rotateAxis(camaraPersonal.getBack().getYAxis(), -0.02f);
           
           if (derecha) camaraPersonal.rotateAxis(camaraPersonal.getBack().getYAxis(), 0.02f);
           
           if (salto)
               if (Mundo.checkCameraCollision (Camera.CAMERA_MOVEUP, alturaPersonal, alturaPersonal*4/3, true))
                   camaraPersonal.moveCamera (Camera.CAMERA_MOVEUP, velocidadPersonal);
           
           if (agache) camaraPersonal.moveCamera (Camera.CAMERA_MOVEDOWN, velocidadPersonal/2);
           if (salida) System.exit (0);
       }
       catch (Exception E) {
           
       }
   }


Well, the gravity done on the second line works good, the problem is when moving the camera to the front and back.

If I have to use another kind of collision detection please could someone explain me why and how?.
Nada por ahora

EgonOlsen

Don't use checkCameraCollision()...it's ancient stuff that doesn't work well in all cases. I strongly suggest to use checkCameraCollisionEllipsoid instead. Have a look at the fps example to see how to.

Melssj5

Well, after 24 hours breaking my soul I did it.

The collision detection really brang me troubles, I just couldnt understand why does my Colli... didnt worked. It result being easy, the problem was that as the checkCameraCollisionEllipsoid and the checkCameraCollisionSpherical return a boolean depending if they collide or not, I thought that the methods only returns the result of CHECKING for a collision, but in fact they do more than that. They also move the camera, thats why I was moving the camera more than once for every movement. And also the speed have to be set in that method.

A suggestion is to do a method that only checks for a collision, it may be useful, when I learned programming in java (a year ago), I learned that a method should do only its specific task, thats why when I read the name of the method checkCameraCollision......, I thought that it only checks it.

Well, its just my opinion.
Nada por ahora

EgonOlsen

Sorry for confusing you with the methods' naming.  In earlier versions, naming was different (something like moveCameraCollision IIRC, which was bogus too). But i agree that the naming is not that good. I just couldn't come up with anything better at that time and now...now i'll leave it this way... :wink:

EgonOlsen

Quote from: "Melssj5"A suggestion is to do a method that only checks for a collision, it may be useful.
It is there. checkCollisionEllipsoid does exactly that. Again, the fps example should help to clarify this.