So this is kicking me a little bit. Works from -x and +x direction. -z works, -y works. But if I collide in the +z or +y it goes haywire (pushes the cube to the nearest corner)
Edit to add. Reversing the operators works as I originally intended. Pull the cube in, and trap it. Though the same directions would free the cube.
float DirXdistP1andWH = initPosTransCubeX - initPosWormHoleX;
float DirYdistP1andWH = initPosTransCubeY - initPosWormHoleY;
float DirZdistP1andWH = initPosTransCubeZ - initPosWormHoleZ;
float XdistP1andWH = std::fabs(initPosTransCubeX - initPosWormHoleX);
float YdistP1andWH = std::fabs(initPosTransCubeY - initPosWormHoleY);
float ZdistP1andWH = std::fabs(initPosTransCubeZ - initPosWormHoleZ);
if (XdistP1andWH <= P1Width && YdistP1andWH <= P1Height && ZdistP1andWH <= P1Depth ) {
if ((DirXdistP1andWH >= -(P1Width)) && (DirXdistP1andWH >= (DirYdistP1andWH || DirZdistP1andWH))) {
initPosTransCubeX += (P1Width - XdistP1andWH);
}
else if ((DirYdistP1andWH >= -(P1Height)) && (DirYdistP1andWH >= (DirXdistP1andWH || DirZdistP1andWH)) ) {
initPosTransCubeY += (P1Height - YdistP1andWH);
}
else if ((DirZdistP1andWH >= -(P1Depth)) && (DirZdistP1andWH >= (DirXdistP1andWH || DirYdistP1andWH)) ) {
initPosTransCubeZ += (P1Depth - ZdistP1andWH);
}
else if ((DirXdistP1andWH <= P1Width) && (DirXdistP1andWH <= (DirYdistP1andWH || DirZdistP1andWH)) ) {
initPosTransCubeX -= (P1Width - XdistP1andWH);
}
else if ((DirYdistP1andWH <= P1Height) && (DirYdistP1andWH <= (DirXdistP1andWH || DirZdistP1andWH)) ) {
initPosTransCubeY -= (P1Height - YdistP1andWH);
}
else if ((DirZdistP1andWH <= P1Depth) && (DirZdistP1andWH <= (DirXdistP1andWH || DirYdistP1andWH)) ) {
initPosTransCubeZ -= (P1Depth - ZdistP1andWH);
}
}