PDA

View Full Version : 3D Collision problems



steffen1296
03-01-2013, 09:09 AM
i have 2 3D cubes one which is moving and the other is stands in the Map.
But if the Camera cube is touching the other cube, the cube gets stuck in some positions

Collision Class:

public static boolean Checkfront(float camx, float camy, float camz)
{
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;

if (x - 1.03 < camx && x + 1 > camx || x == camx){
if (y < camy && y + 1 > camy || y == camy){
if (z < camz && z + 1 > camz || z == camz){
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}

public static boolean Checkleft (float camx, float camy, float camz)
{
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;

if (x - 1.03 < camx && x > camx || x - 1 == camx){
if (y < camy && y + 1 > camy || y == camy){
if (z - 1 < camz && z + 1 > camz || z == camz){
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}

public static boolean Checkback (float camx, float camy, float camz)
{
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;

if (x - 1.03 < camx && x + 1 > camx || x == camx){
if (y < camy && y + 1 > camy || y == camy){
if (z - 1 < camz && z + 1 > camz || z == camz){
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}

public static boolean Checkright (float camx, float camy, float camz)
{
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;

if (x + 1.03 > camx || x == camx){
if (y < camy && y + 1 > camy || y == camy){
if (z - 1.03 < camz && z + 1 > camz || z == camz){
return true;
}else{
return false;
}
}else{
return false;
}
}else{
return false;
}
}

Move Class:

public static void PlayerControle()
{
if(Keyboard.isKeyDown(Keyboard.KEY_W) && physic.Checkforne(x, y, z) == false){
z -= speed * Math.sin(Math.toRadians(ry +90 * 1));
x -= speed * Math.cos(Math.toRadians(ry -90 * 1));
Player1Cam.posz = -z - 5;
}
if(Keyboard.isKeyDown(Keyboard.KEY_S) && physic.Checkhinten(x, y, z) == false){
z += speed * Math.sin(Math.toRadians(ry +90 * 1));
x += speed * Math.cos(Math.toRadians(ry -90 * 1));
Player1Cam.posz = -z - 5;
}
if(Keyboard.isKeyDown(Keyboard.KEY_A) && physic.Checkrechts(x,y,z) == false){
z -= speed * Math.sin(Math.toRadians(ry +90 * 0));
x -= speed * Math.cos(Math.toRadians(ry -90 * 0));
Player1Cam.posx = -x - 0.5f;
}
if(Keyboard.isKeyDown(Keyboard.KEY_D) && physic.Checkleft(x,y,z) == false){
z += speed * Math.sin(Math.toRadians(ry +90 * 0));
x += speed * Math.cos(Math.toRadians(ry -90 * 0));
Player1Cam.posx = -x - 0.5f;
}

}

Nowhere-01
03-01-2013, 09:21 AM
this forum is about OpenGL - API for rendering. your question is about processing physics. ask it on gamedev.net or somewhere else.

squills
03-05-2013, 12:45 AM
Did you add the off sets for the near to the equations?