ok, so I created a sphere at the camera and now i'm on the not-so easy task of actually making the collision. I tried this but it dosent even return 1 when the camera is colliding with the level. Anybody tell me why?
void camera_collision()
{
dbSetObjectToCameraOrientation ( 21 );
dbPositionObject(21,dbCameraPositionX(0),dbCameraPositionY(0),dbCameraPositionZ(0));
dbPositionCamera(dbObjectPositionX(21),dbObjectPositionY(21),dbObjectPositionZ(21));
dbHideObject(21);
camera_status=true;
float oldx = dbObjectPositionX(21);
float oldy = dbObjectPositionY(21);
float oldz = dbObjectPositionZ(21);
float angy = dbObjectAngleY(2000);
dbYRotateObject( 2000,dbObjectAngleY(2000) + dbMouseMoveX()/3.0f );
dbXRotateObject( 2000,dbObjectAngleX(2000) + dbMouseMoveY()/3.0f );
if (dbKeyState(32) == 1 ) {
//right
vx = vx + dbCos(angy); vz = vz - dbSin(angy); }
if (dbKeyState(30) == 1 ) { //left
vx = vx - dbCos(angy); vz = vz + dbSin(angy); }
if (dbKeyState(31) == 1 ) { // back
vx = vx - dbSin(angy); vz = vz - dbCos(angy); }
if (dbKeyState(17) == 1 ) { //forward
vx = vx + dbSin(angy); vz = vz + dbCos(angy); }
dbYRotateObject( 21,dbObjectAngleY(21) + dbMouseMoveX()/3.0f );
dbXRotateObject( 21,dbObjectAngleX(21) + dbMouseMoveY()/3.0f );
float x = oldx + vx;
float y = oldy + vy;
float z =oldz + vz;
int collide_cam = SC_SphereCastGroup( 1, oldx,oldy,oldz, oldx,oldy+vy,oldz, 4,0 );
if ( collide_cam > 0 )
{
x = x - oldx; z = z - oldz;
oldx = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
oldz = SC_GetCollisionSlideZ();
x = x + oldx; z = z + oldz;
}
dbPositionObject( 21,x,oldy,z );
}