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?
How are you rendering? Do you use full processing time (no sleep)?
If you do, than it is possible that when you rotate it, more objects needs to be rendered or something like that and that causes that movement is much slower. Since one rendering loop takes longer.
no, it's a test with 2 objects only... a cube as moving object and a plane as a map (small, whole visible all the time)
I'm wondering if the cube.getZAxis() doesn't do it
What's the purpose of this section:
moveResultant.x=Math.round(moveResultant.x*10)/10f;
moveResultant.y=Math.round(moveResultant.y*10)/10f;
moveResultant.z=Math.round(moveResultant.z*10)/10f;
It does reduce accuracy by a good amount. Anything else?
damn, after commenting it out everything is cool :/
in my old DirectX game i used such thing to round to the second number after the comma so that I don't have someting like 0.0000000000001...
that's why I added it as soos as I added the "resultant vector movement" technique
thanks