Thanks jezza! Did some changes, but it partially works, because the it doesn't actually goes all the way around, and kinda get's stuck in the middle.
Later: agh.. dunno what i changed, now it just stays in place :\
#include "DarkGDK.h"
#include "SC_Collision.h"
#include "math.h"
void MovementSiColliziune();
void DebugObjectMovement();
float gravity = -0.28f;
float radius = 2;
float radious = 0.7;
int playervar = 2;
float playerspeed = 1;
float gravspeed = 0;
float px;
float py;
float pz;
float dist;
float G = 6.67428 * pow(10.0,-11);
float acceleration;
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDisplayModeAntialias(1024,768,32,1,18,0);
dbAutoCamOff();
SC_Start( );
//World - 1
//dbMakeObjectSphere(1,20);
//dbLoadObject("planet.X",1);
dbMakeObjectSphere(1,50);
SC_SetupComplexObject(1,1,2);
//Player - 2
dbMakeObjectCube(playervar,radius);
dbPositionObject(playervar,dbObjectPositionX(1),dbObjectPositionY(1)+30,dbObjectPositionZ(1));
SC_SetupObject(playervar,0,0);
//Debug Object
dbMakeObjectCube(5,1);
dbColorObject(5,dbRGB(255,0,0));
dbPositionObject(5,dbObjectPositionX(1),dbObjectPositionY(1)+30,dbObjectPositionZ(1));
SC_SetupObject(5,0,0);
while ( LoopGDK ( ) )
{
MovementSiColliziune();
dbSetCameraToFollow(dbObjectPositionX(playervar),dbObjectPositionY(playervar),dbObjectPositionZ(playervar),dbObjectAngleY(playervar),20,6,10,0);
dbSync ( );
}
return;
}
void MovementSiColliziune()
{
float oldx = dbObjectPositionX(playervar);
float oldy = dbObjectPositionY(playervar);
float oldz = dbObjectPositionZ(playervar);
dbPositionObject(5,oldx,oldy,oldz);
//Movement
if(dbKeyState(17))
{
dbMoveObject(playervar,playerspeed);
}
if(dbKeyState(31))
{
dbMoveObject(playervar,playerspeed);
}
px = dbObjectPositionX(1)-dbObjectPositionX(playervar);
py = dbObjectPositionY(1)-dbObjectPositionY(playervar);
pz = dbObjectPositionZ(1)-dbObjectPositionZ(playervar);
dist = (px*px)+(py*py)+(pz*pz);
acceleration = 0-(2000000000*G)/dist;
//acceleration/=dbScreenFPS();
gravspeed-=acceleration;
dbPointObject(5,dbObjectPositionX(1),dbObjectPositionY(1),dbObjectPositionZ(1));
dbMoveObject(5, gravspeed);
dbPositionObject(playervar,dbObjectPositionX(5),dbObjectPositionY(5),dbObjectPositionZ(5));
float newx = dbObjectPositionX(playervar);
float newy = dbObjectPositionY(playervar);
float newz = dbObjectPositionZ(playervar);
int collide = SC_SphereSlideGroup( 1, oldx,oldy,oldz, newx,newy,newz,radious, 0 );
if(collide)
{
dbPositionObject(playervar,SC_GetCollisionSlideX(),SC_GetCollisionSlideY(),SC_GetCollisionSlideZ());
}
//dbPositionObject(5,dbObjectPositionX(playervar),dbObjectPositionY(playervar),dbObjectPositionZ(playervar));
if(dbKeyState(30))
{
dbYRotateObject(playervar,dbObjectAngleY(playervar)-1);
}
if(dbKeyState(32))
{
dbYRotateObject(playervar,dbObjectAngleY(playervar)+1);
}
}
I just can't understand what i am doing wrong. So, let's recap:
- I make two objects, a playercube and a "gravity"cube. I point the gravity cube towards the center of the sphere, and position the playercube at the gravity cube's position. I check for collision, and position the playercube on the surface of the "planet", and then, at the start of the new loop i position the gravity cube at the same position as the playercube :\