Im trying to set up a game level with a generated terrain. There will be various creatures throughout (hoping to use some type of spawn-in system) and various buildings in specific locations that you can enter. The problem I am currently having is with object collision. First I tried setting it up manually with dbMakeObjectCollisionBox, dbSetObjectCollisionOn, and dbSetObjectRadius. Then, I tried working with the AutoCollision commands and GlobalCollision. I fear my noobism has got the best of me, any help would be appreciated!
The following snippet uses resources found in the DGDK tutorials if you wanna fire it up
#include "DarkGDK.h"
float g_fCamDistance = 100.0f;
float g_fCamAngle = 45.0f;
void DarkGDK(void) {
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetGlobalCollisionOn();
dbAutoCamOff();
dbSetCameraRange ( 1.0f, 5000.0f );
dbSetCurrentCamera(1);
//dbAutomaticCameraCollision(1, 20, 1);
dbPrint ( "LOADING..." );
dbSync ( );
dbSync ( );
// terrain
dbLoadImage ( "texture.jpg", 1 );
dbLoadImage ( "detail.jpg", 2 );
dbSetupTerrain ( );
dbMakeObjectTerrain ( 1 );
dbSetTerrainHeightMap ( 1, "map.bmp" );
dbSetTerrainScale ( 1, 20.0f, 1.0f, 20.0f );
dbSetTerrainLight ( 1, 1.0f, -0.25f, 0.0f, 1.0f, 1.0f, 0.78f, 0.5f );
dbSetTerrainTexture ( 1, 1, 2 );
dbBuildTerrain ( 1 );
dbAutomaticObjectCollision(1, 1, 0);
dbUpdateTerrain();
// main character
dbLoadObject("Colonel-X.x", 10);
dbAutomaticObjectCollision(10, 35, 1);
dbPositionObject(10, 750, 0, 450);
dbYRotateObject(10, -135);
// fog
dbFogOn();
dbFogDistance(2000);
dbFogColor(100, 100, 100);
// shapes
dbMakeObjectBox(100, 500, 150, 300);
dbAutomaticObjectCollision(100, 10, 0);
dbPositionObject(100, 1250,
dbGetTerrainGroundHeight(1, 1250, 700) + 75, 700);
// now onto our main loop
while ( LoopGDK ( ) )
{
if (dbUpKey()) {
dbSetObjectSpeed ( 10, 40 );
dbLoopObject(10, 235, 259);
dbMoveObject(10, -1.6f);
if (dbRightKey()) {
dbYRotateObject(10, dbObjectAngleY(10) + 1.5f);
} else if (dbLeftKey()) {
dbYRotateObject(10, dbObjectAngleY(10) - 1.5f);
}
} else if (dbDownKey()) {
dbSetObjectSpeed(10, 25);
dbMoveObject(10, 0.8f);
dbLoopObject(10, 235, 259);
if (dbRightKey()) {
dbYRotateObject(10, dbObjectAngleY(10) + 1.5f);
} else if (dbLeftKey()) {
dbYRotateObject(10, dbObjectAngleY(10) - 1.5f);
}
} else if (dbRightKey() && (!dbUpKey() || !dbDownKey())) {
dbSetObjectSpeed(10, 30);
dbMoveObjectLeft(10, 0.8f);
dbLoopObject(10, 280, 299);
} else if (dbLeftKey() && (!dbUpKey() || !dbDownKey())) {
dbSetObjectSpeed(10, 30);
dbMoveObjectRight(10, 0.8f);
dbLoopObject(10, 260, 279);
} else {
dbSetObjectSpeed ( 10, 20 );
dbLoopObject(10, 210, 234);
}
if (dbScanCode() == 72) {
g_fCamDistance -= 2.0f;
} else if (dbScanCode() == 75) {
g_fCamAngle += 2.0;
} else if (dbScanCode() == 77) {
g_fCamAngle -= 2.0;
} else if (dbScanCode() == 80) {
g_fCamDistance += 2.0f;
}
float fHeight = dbGetTerrainGroundHeight(1, dbObjectPositionX(10), dbObjectPositionZ(10));
dbPositionObject(10, dbObjectPositionX(10), fHeight, dbObjectPositionZ(10));
dbSetCameraToFollow(dbObjectPositionX(10), dbObjectPositionY(10), dbObjectPositionZ(10),
dbWrapValue(g_fCamAngle), g_fCamDistance, 75.0f, 10, true);
dbUpdateTerrain ( );
//dbPrint("FRAME: "); dbPrint(dbObjectFrame(10));
//dbPrint("KEY: "); dbPrint((double)dbScanCode());
dbPrint("LOCATION (X/Z): "); dbPrint(dbObjectPositionX(10));dbPrint(dbObjectPositionZ(10));
dbSync ( );
}
}
I am new to this, but I am confused as to whether I should post in the Newcomers forum. Considering that it is titled 'DB Newcomers', and I am using GDK. Could someone clarify whether or not I should post my 'GDK Newcomer' questions there?