SC_SetupComplexObject(2,2,2); sort of works but now the player just slides off the level even if the collision function isnt being used and the X coordinate isnt being updated it stays the same the level is just a flat plane
#include "DarkGDK.h"
#include "SC_Collision.h"
void MakePlayer( int iId, float fx, float fy, float fz );
void level( int iID, float fx, float fy, float fz );
void collision( int iID);
void movement();
float CameraAngleX = 0.0f;
float CameraAngleY = 0.0f;
float slope = 0.5f;
int jumptimer = 1;
float radius = 7.0f;
float gravity = -0.1;
int ground = 1;
float vx = 0;
float vy = 0;
float vz = 0;
float dy = 0;
// 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 );
SC_Start();
// our main loop
while ( LoopGDK ( ) )
{
MakePlayer(1, dbObjectPositionX(1), dbObjectPositionY(1), dbObjectPositionZ(1) );
level( 2, dbObjectPositionX(2), -3.0f, dbObjectPositionZ(2) );
collision(1);
movement();
// update the screen
dbSync ( );
}
// return back to windows
return;
}
void MakePlayer(int iID, float fx, float fy, float fz)
{
dbMakeObjectCube( 1, 1 );
dbPositionObject(1,fx, fy, fz );
SC_SetupObject( 1,0,2 );
}
void collision(int iID)
{
float oldx = dbObjectPositionX(iID);
float oldy = dbObjectPositionY(iID);
float oldz = dbObjectPositionZ(iID);
float angy = dbObjectAngleY(1);
vx = 0;
vz = 0;
if ( vy == 0 ) vy = vy + 9.8*gravity;
else vy = vy + gravity;
if ( ground == 1 /*&& dbObjectPositionY(iID) < 500.0f */)
{
if ( dbSpaceKey() == 1 || dbJoystickFireB() == 1)
{
vy = vy + 3.0f;
}
}
float x = oldx + vx;
float y = oldy + vy;
float z = oldz + vz;
/*if(dbObjectPositionY(iID) > 500){if ( ny < -slope ) vy = gravity;}*/
int collide = SC_SphereCastGroup( 0, oldx,oldy,oldz, oldx,oldy+vy,oldz,radius,0 );
if ( collide > 0 )
{
float ny = SC_GetCollisionNormalY();
if ( dbAbs(ny) > slope )
{
oldy = SC_GetStaticCollisionY();
}
else
{
x = x - oldx; z = z - oldz;
oldx = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
oldz = SC_GetCollisionSlideZ();
x = x + oldx; z = z + oldz;
}
if ( ny > slope )
{
ground = 1;
vy = 0;
}
else
{
ground = 0;
if ( ny < -slope ) vy = gravity;
}
}
else
{
oldy = oldy + vy;
ground = 0;
}
if ( ground == 1 && jumptimer > 0 ) jumptimer--;
if ( collide > 0 )
{
x = SC_GetCollisionSlideX();
oldy = SC_GetCollisionSlideY();
z = SC_GetCollisionSlideZ();
vx = 0;
vz = 0;
/*dy = oldy - SC_GetStaticCollisionY();
if ( dy < slope && dy > 0 && ground == 1 ) vy = 0.5;*/
}
dbPositionObject( 1,x,oldy,z );
SC_UpdateObject( 1 );
}
void movement()
{
if( dbKeyState( 17 ) )
{
dbMoveObject( 1, 0.2f );
}
if( dbKeyState( 31 ) )
{
dbMoveObject( 1, -0.2f );
}
if( dbKeyState( 30 ) )
{
dbYRotateObject(1, dbObjectAngleY(1) -90 );
dbMoveObject(1, 0.2f );
dbYRotateObject(1, dbObjectAngleY(1) +90 );
}
if( dbKeyState( 32 ) )
{
dbYRotateObject(1, dbObjectAngleY(1) +90 );
dbMoveObject( 1, 0.2f );
dbYRotateObject(1, dbObjectAngleY(1) -90 );
}
dbYRotateObject( 1,dbObjectAngleY(1) + dbMouseMoveX()/3.0f );
dbXRotateObject( 1,dbObjectAngleX(1) + dbMouseMoveY()/3.0f );
dbXRotateCamera ( CameraAngleX );
dbYRotateCamera ( CameraAngleY );
if ( CameraAngleX > 80 && CameraAngleX <180 ) CameraAngleX = 80;
if ( CameraAngleX < 270 && CameraAngleX > 180 ) CameraAngleX = 270;
dbPositionCamera( dbObjectPositionX(1),dbObjectPositionY(1),dbObjectPositionZ(1) );
dbRotateCamera( dbObjectAngleX(1),dbObjectAngleY(1),dbObjectAngleZ(1) );
dbText( 10, 10, dbStr( dbCameraPositionX() ) );
dbText( 10, 50, dbStr( dbCameraPositionY() ) );
dbText( 10, 30, dbStr( dbCameraPositionZ() ) );
}
void level(int iID, float fx, float fy, float fz)
{
dbLoadObject("test level.3DS", 2 );
dbPositionObject( 2, fx - 5, fy, fz );
SC_SetupComplexObject( 2, 2, 2 );
}