If you left click on the object it saves it into a string variable, then if you right click somewhere (only supposed to work if you click above the object atm) it should move to where you click. I have a piece of text that says "target" at the place where you right click so you know where the object is supposed to go. However, the object just keeps going and going, it never stops. The object is attached if that makes any difference.
#include "DarkGDK.h"
#include <string>
using namespace std;
// 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 );
dbAutoCamOff();
dbMaximizeWindow();
dbLoadObject ("tank.x", 1);
dbScaleObject(1, 20, 20, 20);
dbXRotateObject(1, -70);
dbRotateObject(1, dbObjectAngleX(1), dbObjectAngleY(1), dbObjectAngleZ(1) + 181);
int robot = 1;
dbPositionObject(1, dbObjectPositionX(1), dbObjectPositionY(1) - 10, dbObjectPositionZ(1));
dbPositionCamera(0, 0, -500);
string target = " ";
float targetLocationX = 0;
float targetLocationY = 0;
float targetLocationZ = 0;
float cameraX = 0;
float cameraY = 0;
float cameraZ = -500;
// our main loop
while ( LoopGDK ( ) )
{
if (dbPickObject(dbMouseX(), dbMouseY(), robot, robot) == robot)
{
dbText(dbMouseX(), dbMouseY(), "Targeted");
if (dbMouseClick() == 1)
{
target = robot;
}
}
if (dbMouseClick() == 2)
{
if (target != " ")
{
targetLocationX = dbMouseX();
targetLocationY = dbMouseY();
target = " ";
}
}
if (targetLocationY != 0)
{
dbMoveObject(robot, -0.2);
}
if (dbObjectPositionY(1) == targetLocationY)
{
targetLocationY = 0;
dbText(dbMouseX(), targetLocationY, "You are here");
}
if (targetLocationY != 0)
{
dbText(targetLocationX, targetLocationY, "target");
}
// update the screen
dbSync ( );
}
// return back to windows
return;
}