I an trying to make my own first person shooter but I am still a beginner. The problem is that when the two objects (player nr.10 and object nr.5)collision the player will stop but when I keep pressing my arrow keeps the player move through the object. It detects the collision to soon. And I tried it to place SC_SetupObject to boxes but then i saw with SC_DrawObjectBounds that the bounds weren't rescaled but I am using SC_AllowObjectScaling.
#include "DarkGDK.h"
#include "SC_Collision.h"
float gunWaggle = 0.0f;
float gunWaggle2 = 0.0f;
int fCameraAngleX;
int fCameraAngleY;
float vx = 0;
float vy = 0;
float vz = 0;
void DarkGDK(void)
{
dbSyncOn();
dbSyncRate( 60 );
dbHideMouse();
dbLoadImage ("terrain/texture.jpg", 1);
dbLoadImage ("terrain/detail.jpg", 2);
dbLoadImage("dual elites/crosshair.dds",12);
dbLoadObject("atomiser.x",10);
dbRotateObject(10 ,-90, 0 , 0);
dbFixObjectPivot(10);
dbDisableObjectZDepth(10);
//dbSetObjectCollisionToBoxes(10);
dbSetCameraRange(1.0f, 30000.0f);
dbLoadObject("skybox2.x", 2);
dbSetObjectLight(2, 0);
dbSetObjectTexture(2, 3, 2);
dbScaleObject(2, 30000, 30000, 30000);
dbSetupTerrain();
dbMakeObjectTerrain(1);
dbSetTerrainHeightMap(1, "terrain/map.bmp");
dbSetTerrainScale(1, 3.0f, 0.6f, 3.0f);
dbSetTerrainLight(1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f);
dbSetTerrainTexture(1, 1, 2);
dbBuildTerrain(1);
dbLoadImage("gunfire1.png",100,0);
dbMakeObjectBox(11, 3 , 3, 0);
dbTextureObject(11, 100);
dbFadeObject(11, 8000);
dbSetObjectTransparency(11 , 1);
dbHideObject(11);
dbSetObjectCollisionOff(11);
dbPositionObject(11,dbObjectPositionX(10) +1, dbObjectPositionY(10) -1.25, dbObjectPositionZ(10));
dbMoveObjectRight(11, 1.55f);
dbMoveObject(11, 8);
dbMoveObjectDown(11, 0.2f);
dbLockObjectOn(11);
dbLoadObject("move.x", 5);
dbPositionObject(5, 573.19, 0, 469.18);
dbScaleObject(5, 700, 700, 700);
dbSetObjectLight(5, 0);
//dbSetObjectCollisionToBoxes(5);
dbLoadSound("gun1.wav", 21);
dbSetSoundSpeed(21, 88000);
dbPositionCamera(152, 27, 90);
SC_Start();
SC_SetObjectCollisionOn(10);
SC_SetObjectCollisionOn(5);
SC_SetupObject(5,1,0);
SC_SetupObject(10,2,0);
SC_AllowObjectScaling(5);
while (LoopGDK ())
{
float oldx = dbObjectPositionX(10);
float oldy = dbObjectPositionY(10);
float oldz = dbObjectPositionZ(10);
dbPrint(dbCameraPositionX()); //getting in game coordinates
dbPrint(dbCameraPositionY());
dbPrint(dbCameraPositionZ());
dbPositionMouse(dbScreenWidth()/ 2, dbScreenHeight()/ 2);
dbPasteImage(12, ( dbScreenWidth()/ 2), ( dbScreenHeight()/ 2) - 16, 1);
float x = dbObjectPositionX(10);
float y = dbObjectPositionY(10);
float z = dbObjectPositionZ(10);
int collide = 0;
collide = SC_ObjectCollision (10, 5);
if(dbUpKey()==1)
{
if (collide > 0)
{
dbPositionObject (10, oldx, oldy, oldz);
}
else
{
dbMoveCamera(2);
gunWaggle += 0.55f;
gunWaggle2 += 0.25f;
}
}
if (dbDownKey() == 1)
{
if (collide > 0)
{
dbPositionObject (10, oldx, oldy, oldz);
}
else
{
dbMoveCamera(-2);
gunWaggle += 0.55f;
gunWaggle2 += 0.25;
}
}
if (dbLeftKey() == 1)
{
if (collide > 0)
{
dbPositionObject (10, oldx, oldy, oldz);
}
else
{
dbYRotateCamera(0, dbCameraAngleY() -90);
dbMoveCamera(2);
}
}
if (dbRightKey() == 1)
{
if (collide > 0)
{
dbPositionObject (10, oldx, oldy, oldz);
}
else
{
dbYRotateCamera(0 , dbCameraAngleY() +90);
dbMoveCamera(2);
}
}
SC_UpdateObject(10);
fCameraAngleX = dbWrapValue(fCameraAngleX +dbMouseMoveY() *0.2f);
fCameraAngleY = dbWrapValue(fCameraAngleY +dbMouseMoveX() *0.2f);
dbXRotateCamera(fCameraAngleX);
dbYRotateCamera(fCameraAngleY);
dbSetObjectToCameraOrientation (10);
dbPositionObject(10, dbCameraPositionX(), dbCameraPositionY(), dbCameraPositionZ());
dbMoveObjectRight(10, 15 +sin(gunWaggle2/ 2.0f)/ 2.0f);
dbMoveObject(10, 15.0f);
dbMoveObjectDown(10, 15.0f +cos(gunWaggle/ 2.0f)/ 2.0f);
gunWaggle += 0.2f;
if (dbMouseClick() == 1)
{
gunWaggle2 += 1.55f;
dbPlaySound(21);
dbLoopSound(21,0,10000,0);
dbShowObject(11);
dbRollObjectLeft (11 ,(float)(rand() %360));
}
else
{
dbPauseSound(21);
dbHideObject(11);
}
float fHeight = dbGetTerrainGroundHeight(1, dbCameraPositionX(), dbCameraPositionZ());
dbPositionCamera(dbCameraPositionX(), fHeight +10.0f, dbCameraPositionZ());
dbUpdateTerrain();
dbSync();
}
return;
}