# Detect who face have collision in a Box

Hello!!

I try to make an game like arkanoid. When the ball collision with a block, its has to change their direction according to the normal of the face that which has the collision.

I don't know how detect wich face has collision. More precisely, i want know the normal of the face which has a collision.

Are there any utility (or helpper) class to do this?

thanks

This is the code that i write:

ArrayList<Integer> blockTri = new ArrayList<Integer>();

ArrayList<Integer> ballTri = new ArrayList<Integer>();

block.findTriangleCollision(ball, blockTri, ballTri);

int[] storage = new int;

block.getTriangle(blockTri.get(0), storage);

Then, the variable "storage" has the triangle's points but I don't know how get the normal.

Are there a better way to do this?

Hello H

Hello again!

Here I attach a slightly modified version of the code I used…

```                 if(node1.hasCollision(node2, false))                 {                     CollisionResults results = new TriangleCollisionResults() {                         @Override                         public void processCollisions() {;} //not really needed to implement this                     };                     FloatBuffer normalBuffer;                     node1.findCollisions(node2, results);                     for (j=-1;++j<results.getNumber(); )                     { //If we have a collision between bounding boxes                         CollisionData collisionData = results.getCollisionData(j); //get the collision data                         int numTris=collisionData.getTargetTris().size();                                                 for(k=-1;++k<numTris; ) //If an actual triangle has collided (rather than just the bounding box) loop through them                         {                             TriMesh geom=(TriMesh)collisionData.getTargetMesh();                             int triIndex=collisionData.getTargetTris().get(k);                                                     int[]vertices=new int;                             geom.getTriangle(triIndex, vertices);                             normalBuffer=geom.getWorldNormals(null);                                                     normalBuffer.position(vertices*3); //This position should be the first vertex normal and so on :P                             normalBuffer.position(vertices*3);                             normalBuffer.position(vertices*3);                         }                     }                 } ```

I know it seems a little nasty, but I works as expected (and I didn't find a better way...).

Hello joliver82!

I will check this code. Thanks very much. If i find a better way for do this, i'll post it. Thanks again.

Hi, I'm using this code to calculate the normals for collisions in some of my work.  It works great with objects normally but I'm having problems with getting it to return the normals for collisions with orthogonal objects.  Its just returns the z axis which I guess is down to the orthogonals' flat nature.  Does anyone know a way of getting the correct collision vector for orthogonal objects?

Thanks.