Okay well i found a tutorial on collusion and here is my full code.. But collision doesn't work! Its really making me mad why it wont work i dont understand it.
#include <DarkGDK.h>
#include <SC_Collision.h>
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;
float my,mx;
void ThirdPerson (int obj)
{
my = dbMouseMoveY ( );
mx = dbMouseMoveX ( );
float x1 = dbCameraAngleX ();
float y1 = dbCameraAngleY ();
float z1 = dbCameraAngleZ ();
dbPositionCamera( dbObjectPositionX(obj),dbObjectPositionY(obj),dbObjectPositionZ(obj) );
dbRotateCamera( dbObjectAngleX(obj),dbObjectAngleY(obj),dbObjectAngleZ(obj) );
dbPitchCameraDown (30);
dbMoveCamera( -150 );
if (dbMouseClick() == 2)
{
dbPointCamera (x1,y1,z1);
fCameraAngleX = dbWrapValue ( fCameraAngleX + my * 0.4f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + mx * 0.4f );
dbPositionMouse (dbScreenWidth() /2, dbScreenHeight() /2);
dbXRotateCamera (fCameraAngleX );
dbYRotateObject (obj, fCameraAngleY);
dbYRotateCamera (fCameraAngleY );
dbHideMouse();
}
else
{
dbPointCamera (dbObjectPositionX (obj),dbObjectPositionY (obj), dbObjectPositionZ(obj));
dbPitchCameraUp (20);
dbShowMouse();
}
}
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
SC_Start( );
// Walls.
dbMakeObjectBox(1, 100, 100, 16);
dbMakeObjectBox(2, 100, 100, 16);
dbPositionObject(1, 50, 50, 100);
dbPositionObject(2, 200, 50, 50);
SC_SetupObject(1, 1, 2); // Groups other than ZERO for stuff you hit
SC_SetupObject(2, 1, 2); // reserve ZERO for your player :)
// I think this is a good idea - I'm not sure you can have a group item hit something
// in the same group. That MIGHT be an issue you came across and didn't know it.
// Player.
dbMakeObjectCube(3, 32);
dbPositionObject(3, 0, 16, 0);
SC_SetupObject(3, 2, 2);
// Camera Object.
//dbMakeObjectCube(4, 100);
//dbHideObject(4);
//SC_SetupObject(4, 0, 2);
// Old Values. (More Efficient I THINK declaring up here).
// maybe no difference seeing how SCOPE didn;t change... anyways...
float ox;
float oy;
float oz;
float oax;
float oay;
float oaz;
int iCollideID=0;
while ( LoopGDK ( ) )
{
//float ay = dbObjectAngleY(3);
// Old Values.
//ox = dbCameraPositionX();
//oy = dbCameraPositionY();
//oz = dbCameraPositionZ();
ox =dbObjectPositionX(3);
oy =dbObjectPositionY(3);
oz =dbObjectPositionZ(3);
oax = dbObjectAngleX(3);
oay = dbObjectAngleY(3);
oaz = dbObjectAngleZ(3);
//Player Controls
if (dbKeyState(17)) {
// W Move Forward
dbMoveObject (3,1);
}
if (dbKeyState(16)){
// q straffe left
dbMoveObjectLeft(3,1);
}
if (dbKeyState(18)) {
// e straffe Right
dbMoveObjectRight(3,1);
}
if (dbKeyState(30)){
// A Turn left
dbTurnObjectLeft(3,1);
}
if (dbKeyState(32)) {
// D Turn Right
dbTurnObjectRight(3,1);
}
if (dbKeyState(31)){
// S Move Back
dbMoveObject(3,-1);
}
iCollideID = SC_GroupCollision(3,1);// your Box, and Group 1
if(iCollideID>0){
dbPositionObject(3,ox,oy,oz);
dbRotateObject(3,oax,oay,oaz);
};
// I move the Camera Object.
//float cz = dbNewZValue(dbObjectPositionZ(3), dbWrapValue(ay + 180), 100);
//float cx = dbNewXValue(dbObjectPositionX(3), dbWrapValue(ay + 180), 100);
//dbPositionObject(4, cx, dbObjectPositionY(3) + 30, cz);
//dbRotateObject(4, dbObjectAngleX(3), dbObjectAngleY(3), dbObjectAngleZ(3));
// Camera Object collision.
//if (dbObjectCollision(4, 0) > 0)
//{
// dbPositionObject(4, ox, oy, oz);
// dbRotateObject(4, oax, oay, oaz);
//}
// I place the camera.
//dbPositionCamera(dbObjectPositionX(4), dbObjectPositionY(4), dbObjectPositionZ(4));
//dbRotateCamera(dbObjectAngleX(4), dbObjectAngleY(4), dbObjectAngleZ(4));
dbSetCursor(0,0);
dbPrint(dbStr(iCollideID));
dbSync ( );
//Camera View
ThirdPerson(3);
}
return;
}