I've been trying to follow the sliding demo included in sparky's collision, and so far nothing is really working. The character still goes through other objects and the terrain. I don't know if it's because the terrain isn't a .x file(I used terrain tutorial in the dark dgk tutorial folder) and/or if the fact that the character flies and gravity doesn't/shouldn't really apply to it.
So anyway, here's the code:
#include "DarkGDK.h"
#include "SC_Collision.h"
void DarkGDK ( void )
{
SC_Start();
dbSyncOn ( );
dbSyncRate ( 60 );
dbPrint("Loading...");
dbSync();
dbSync();
dbLoadImage ( "texture.jpg", 1 );
dbLoadImage ( "detail.jpg", 2 );
dbSetupTerrain ( );
dbMakeObjectTerrain ( 1 );
dbSetTerrainHeightMap ( 1, "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 );
dbLoadObject ( "skybox2.x", 2 );
dbSetObjectLight ( 2, 0 );
dbScaleObject ( 2, 50000, 50000, 50000 );
dbSetObjectTexture ( 2, 3, 1 );
dbLoadObject("daisy.x", 3);
SC_SetupComplexObject(2, 1, 2);
SC_AllowObjectScaling(2);
SC_SetObjectCollisionOn(2);
dbPositionObject(3, 15, 52, 500);
dbScaleObject(3, 1.5, 1.5, 1.5);
dbLoadObject("d2.x", 4);
SC_SetupObject(3, 1, 2);
SC_AllowObjectScaling(3);
SC_SetObjectCollisionOn(3);
dbPositionObject(4, 15, 52, 560);
dbScaleObject(4, 1.5, 1.5, 1.5);
dbLoadObject("d3.x", 5);
SC_SetupComplexObject(4, 1, 2);
SC_AllowObjectScaling(4);
SC_SetObjectCollisionOn(4);
dbPositionObject(5, 25, 52, 540);
dbScaleObject(5, 1.5, 1.5, 1.5);
dbLoadObject("butterfly.x", 6);
SC_SetupComplexObject(1, 1, 2);
SC_AllowObjectScaling(1);
SC_SetObjectCollisionOn(1);
dbPositionObject(6, 15, 55, 490);
dbScaleObject(6, 5, 5, 5);
dbLoopObject (6);
dbSetObjectSpeed(6, 15000);
dbMakeCamera(7);
dbPositionCamera(7,20,60,490);
dbSetCameraToObjectOrientation(1,1);
while ( LoopGDK ( ) )
{
float YAngle;
float R;
dbSetCameraToFollow(7, dbObjectPositionX(6), dbObjectPositionY(6), dbObjectPositionZ(6), YAngle+R, 10, 11, 1, 0);
dbPointCamera(7,dbObjectPositionX(6), dbObjectPositionY(6), dbObjectPositionZ(6));
if(dbSpaceKey())
{
dbMoveObject(6, .5);
}
if(dbLeftKey())
{
dbTurnObjectLeft(6, 1);
}
if(dbRightKey())
{
dbTurnObjectRight(6, 1);
}
if(dbUpKey())
{
dbPitchObjectUp(6, 1);
}
if(dbDownKey())
{
dbPitchObjectDown(6, 1);
}
float gravity = -0.1f;
int ground = 1;
float vx = 0;
float vy = 0;
float vz = 0;
float radius = 7.0f;
float slope = 0.5f;
float oldx = dbObjectPositionX(2);
float oldy = dbObjectPositionY(2);
float oldz = dbObjectPositionZ(2);
float x = oldx + vx;
float y = oldy + vy;
float z = oldz + vz;
int collide = SC_SphereCastGroup( 1, oldx,oldy,oldz, oldx,oldy+vy,oldz, radius,0 );
float ny = SC_GetCollisionNormalY();
if ( dbAbs(ny) > slope )
{
//FLAT, stick
oldy = SC_GetStaticCollisionY();
}
else
{
//STEEP, slide
x = x - oldx; z = z - oldz;
oldx = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
oldz = SC_GetCollisionSlideZ();
x = x + oldx; z = z + oldz;
}
if ( ny > slope )
{
//only on ground if standing on flat ground
ground = 1;
vy = 0;
}
else
{
ground = 0;
//if player has hit a flat ceiling then stop vy# movement
if ( ny < -slope ) vy = gravity;
}
/*if(SC_ObjectCollision(1, 2)== 1)
{
dbHideObject(2);
//dbHideObject(4);
//dbHideObject(5);
}*/
dbUpdateTerrain ( );
dbSync ( );
}
}
Any help would be very much appreciated. Thanks in advance.