Hello everybody, I've been looking through all the documentation and samples given with Sparky's but I just can't seem to get anything but the most basic sliding collision working.
Here's my code so far:
dbMakeObjectSphere(1,10);
dbPositionObject(1,90,55,37.5);
SC_SetupObject(1,0,1);
dbMakeObjectPlain(100,100,75);
dbMakeObjectPlain(101,100,150);
dbMakeObjectPlain(102,100,75);
dbRotateObject(100,270,0,45);
dbRotateObject(101,270,0,0);
dbRotateObject(102,270,180,-45);
dbPositionObject(100,85,35,37.5);
dbPositionObject(102,85,-35,-37.5);
SC_SetupObject(100,1,0);
SC_SetupObject(101,1,0);
SC_SetupObject(102,1,0);
/*
if(!mainMenu())
{
dbEnd();
exit(0);
}
*/
float oldX,oldY,oldZ,curX,curY,curZ,movX,movY,movZ;
int collision;
float colNormal;
while(LoopGDK())
{
if(dbEscapeKey())break;
dbPositionMouse(640,512);
//old position(current position) of object
oldX=dbObjectPositionX(1);
oldY=dbObjectPositionY(1);
oldZ=dbObjectPositionZ(1);
//setting the movement vector
movX=0;
movY=-0.1f;
movZ=0;
//mathematical final position
curX=oldX+movX;
curY=oldY+movY;
curZ=oldZ+movZ;
//test the final position
collision=SC_SphereCastGroup(0,oldX,oldY,oldZ,oldX,curY,oldZ,5,0);
if(collision>0)
{
curX-=oldX;curZ-=oldZ;
oldX=SC_GetCollisionSlideX();
oldY=SC_GetCollisionSlideY();
oldZ=SC_GetCollisionSlideZ();
curX+=oldX;curZ+=oldZ;
}
collision=SC_SphereSlideGroup(0,oldX,oldY,oldZ,curX,oldY,curZ,5,0);
if(collision>0)
{
curX=SC_GetCollisionSlideX();
oldY=SC_GetCollisionSlideY();
curZ=SC_GetCollisionSlideZ();
movX=0;
movZ=0;
}
else
{
oldY-=0.1f;
}
dbPositionObject(1,curX,oldY,curZ);
SC_UpdateObject(1);
dbControlCameraUsingArrowKeys(0,5,2.5);
dbSync();
}
Note: Obviously not all of it, just the setup and collision code it self.
This code makes object #1, the sphere I want to slide down the plains, fly upwards. I have no idea why. Can anyone help me out?
EDIT:Updated code to reflect latest attempt, sphere still flies upwards.