Posted: 28th Jun 2009 16:53
I am trying to set collision on this 3d Object with a 3d cube and with the level. But the the player goes through the level and the cube,can somebody tell me where i am missing,
[#include "DarkGDK.h"
float ground,jumptimer;
float fCameraAngleX,fCameraAngleY;
float CameraAngleX,CameraAngleY;
float OldCamAngleX,OldCamAngleY;
float gravity;
float oldx,oldy,oldz;
float vx,vy,vz;
float angy;
float x,y,z,a,d,h,s;
void MovePlayerWithKeys(int Mdl);
void positionCameraToPlayer(int Mdl);
void MovePlayerWithMouse(int Mdl);
void LoadModel(int Mdl);
void LoadLevel(int Lvl);
void LoadSkBox(int Lvl);
void LoadBox(int Mdl);
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbPrint ( "Please wait loading model..." );
dbSync ( );
dbSync ( );
// switch to the media directory, load our world
// and turn lighting off
SetCurrentDirectory ( "media" );
//Load Player
LoadModel(3);
//Load level
LoadLevel(1);
// load a model for our sky
LoadSkBox(2);
// position the camera
dbPositionCamera ( 434, 42, -467 );
//dbAutomaticCameraCollision ( 0, 2 , 1 );
//Load a Box
LoadBox(4);
//dbSetGlobalCollisionOn ();
//dbAutomaticCameraCollision(0,2,1);
// camera variables
fCameraAngleX = 0.0f;
fCameraAngleY = 0.0f;
gravity = -0.1f;
jumptimer=1;
ground=1;
// our main loop
while ( LoopGDK ( ) )
{
MovePlayerWithMouse(3);
MovePlayerWithKeys(3);
positionCameraToPlayer(3);
//dbAutomaticObjectCollision ( 3, 10, 1 );
// update the screen
dbSync ( );
}
// return back to windows
return;
}
void LoadModel(int Mdl)
{
dbLoadObject ( "Colonel-X.X", Mdl );
dbSetObjectSpecular(Mdl,0);
dbPointObject(Mdl,0,0,0);
dbFixObjectPivot(Mdl);
dbRotateObject(Mdl,0,180,-0);
dbScaleObject(Mdl,100,75,100);
dbPositionObject(Mdl,434,42,-517);
//dbSetShadowShadingOn(Mdl);
dbLoopObject(Mdl,2497,2696);
dbSetObjectSpeed(Mdl,50);
dbSetObjectCollisionOn(Mdl);
dbSetObjectCollisionToBoxes(Mdl);
}
void LoadLevel(int Lvl)
{
dbLoadObject ( "universe.dbo", Lvl );
dbSetObjectLight ( Lvl, 0 );
}
void LoadSkBox(int Lvl)
{
dbLoadObject ( "skybox2.x", Lvl );
dbSetObjectLight ( Lvl, 0 );
dbSetObjectTexture ( Lvl, 3, 2 );
dbScaleObject ( Lvl, 5000, 5000, 5000 );
}
void LoadBox(int Mdl)
{
dbMakeObjectCube(Mdl,50);
dbLoadImage("boxtexture.jpg",1);
dbTextureObject(Mdl,1);
dbPositionObject(Mdl,484,42,-567);
dbSetObjectCollisionOn(Mdl);
dbSetObjectCollisionToBoxes(Mdl);
}
void positionCameraToPlayer(int Mdl)
{
x=dbObjectPositionX(Mdl);
y=dbObjectPositionY(Mdl);
z=dbObjectPositionZ(Mdl);
a=dbObjectAngleY(Mdl);
d=-65.0;
h=55.0;
s=50.0;
dbSetCameraToFollow(x,y,z,a,d,h,s,1);
}
void MovePlayerWithMouse(int Mdl)
{
OldCamAngleY = CameraAngleY;
OldCamAngleX = CameraAngleX;
CameraAngleY = dbWrapValue ( CameraAngleY + dbMouseMoveX ( ) * 0.4 );
CameraAngleX = dbWrapValue ( CameraAngleX + dbMouseMoveY ( ) * 0.4 );
dbYRotateObject( Mdl, dbCurveAngle ( CameraAngleY, OldCamAngleY, 24 ));
}
void MovePlayerWithKeys(int Mdl )
{
if (dbUpKey()==1) { dbMoveObject(Mdl,-4);}
if (dbDownKey()==1) { dbMoveObject(Mdl,4);}
if (dbLeftKey()==1) { dbMoveObjectRight(Mdl,4);}
if (dbRightKey()==1) { dbMoveObjectLeft(Mdl,4);}
/*if (dbUpKey()==1) { if (dbObjectCollision(3,4)!=1)dbMoveObject(Mdl,-4);}
if (dbDownKey()==1) { if (dbObjectCollision(3,4)!=1)dbMoveObject(Mdl,4);}
if (dbLeftKey()==1) { if (dbObjectCollision(3,4)!=1)dbMoveObjectRight(Mdl,4);}
if (dbRightKey()==1) { if (dbObjectCollision(3,4)!=1)dbMoveObjectLeft(Mdl,4);}*/
if (dbSpaceKey()==1 && jumptimer==0) {dbMoveObjectUp(Mdl,2); jumptimer = 20;}
if (ground == 1 && jumptimer>0) { jumptimer--;}else{}
}
]