first I do the gravity
SimpleVector theG = cube.checkForCollisionEllipsoid(GRAVITY, CUBE_SIZE, 1);
moveResultant.add(theG);
then I "move" (actually at this point I only set the resultant vector) the cube according to pressed keys
boolean movinDaC = false;
cube.rotateY(MX*0.01f);
if(left && moveResultant.x>-3) {
SimpleVector a = cube.getXAxis();
a.scalarMul(-BASESPEED);
moveResultant.add(a);
movinDaC=true;
}
if(right && moveResultant.x<3) {
SimpleVector d = cube.getXAxis();
d.scalarMul(BASESPEED);
moveResultant.add(d);
movinDaC=true;
}
if(forward && moveResultant.z<3) {
SimpleVector w = cube.getZAxis();
w.scalarMul(BASESPEED);
moveResultant.add(w);
movinDaC=true;
}
if(back && moveResultant.z>-3) {
SimpleVector s = cube.getZAxis();
s.scalarMul(-BASESPEED);
moveResultant.add(s);
movinDaC=true;
}
if(MX!=0) {
camRot+=MX*0.01f;
}
if(MY!=0) {
CAMANGLE-=MY*0.01f;
}
then comes the translaition
moveResultant = cube.checkForCollisionEllipsoid(moveResultant, CUBE_SIZE, 1);
cube.translate(moveResultant);
moveResultant.x=Math.round(moveResultant.x*10)/10f;
moveResultant.y=Math.round(moveResultant.y*10)/10f;
moveResultant.z=Math.round(moveResultant.z*10)/10f;
and if no keys are pressed I do the velocity loss
if(!movinDaC) {
if(moveResultant.x>FRICTION) {
moveResultant.x-=FRICTION;
} else if(moveResultant.x<-FRICTION) {
moveResultant.x+=FRICTION;
} else {
moveResultant.x=0f;
}
if(moveResultant.y>FRICTION) {
moveResultant.y-=FRICTION;
} else if(moveResultant.y<-FRICTION) {
moveResultant.y+=FRICTION;
} else {
moveResultant.y=0f;
}
if(moveResultant.z>FRICTION) {
moveResultant.z-=FRICTION;
} else if(moveResultant.z<-FRICTION) {
moveResultant.z+=FRICTION;
} else {
moveResultant.z=0f;
}
}
the SimpleVector CUBE_SIZE is achieved by
float b[] = cube.getMesh().getBoundingBox();
CUBE_SIZE.x = (Math.abs(b[0])+Math.abs(b[1]))/2f;
CUBE_SIZE.y = (Math.abs(b[2])+Math.abs(b[3]))/2f;
CUBE_SIZE.z = (Math.abs(b[4])+Math.abs(b[5]))/2f;
The problem is that if I move forwads it's cool but when I rotate 45 degrees (so it's positioned "diagonally" to global axis) the cube moves very slowly, like ten times slower.
Any ideas what might cause it?