Hi i'm new to DarkGDK so just playing about with some basic stuff but got a little stuck, I have a terrain and a 3d model. I'm trying to program so that when you click on a location on the screen, it will move the model to that location. So far I have this which moves the player in the correct direction but there are a few problems:
1) The player doesn't stop when he gets to the location ( i haven't programmed this yet, wondering if there is a good standard way of doing this)
2) The code will work fine if the terrain is flat but if you steep slopes his ground speed will be increased on those slopes because the functionaility is computed from x,z axises only and doesn't consider y. So he will cover allot more ground in the same time.
Is there a good way around this?
This code sits in the main game loop:
if(dbMouseClick()) {
moving = true; //Player is now moving
int pickVector = dbPickObject ( dbMouseX (), dbMouseY (), 1, 1 ) ; // Pick the mouse location on 2D screen
float xHit = dbGetPickVectorX() + dbCameraPositionX(); //Pick the x and z location on 3d terrain of mouse location
float zHit = dbGetPickVectorZ() + dbCameraPositionZ();
dbSetVector2(1, xHit, zHit ); //Vector from origin to mouse location
dbSetVector2(2, dbObjectPositionX(3), dbObjectPositionZ(3) ); //Vector from origin to object location
dbSubtractVector2(1, 1, 2); //Vector describing movement from object to mouse location
dbNormalizeVector2(1, 1); //Unit or direction vector of this movement
}
if(moving) {
float fHeight = dbGetTerrainGroundHeight ( 1, dbObjectPositionX(3) + dbXVector2(1), dbObjectPositionZ(3) + dbYVector2(1) ); //Y height of next location moving too
dbPositionObject(3, dbObjectPositionX(3) + dbXVector2(1), fHeight, dbObjectPositionZ(3) + dbYVector2(1)); //Move object to new location, of calculated height
float fTanValue = dbYVector2(1)/dbXVector2(1); //Compute angle character should face
float fAngle = 90.0f - dbAtan(fTanValue);
if(dbXVector2(1) > 0) {
fAngle += 180.0f;
}
char cAngle[20];
sprintf ( cAngle , "Rotation: %f" , fTanValue);
dbText(0,0,cAngle);
dbYRotateObject(3,fAngle);
}