Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Move to mouse click location

Author
Message
Tolk
16
Years of Service
User Offline
Joined: 19th Jul 2008
Location:
Posted: 19th Jul 2008 12:52
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:

Dark Gamers
16
Years of Service
User Offline
Joined: 17th Mar 2008
Location:
Posted: 19th Jul 2008 18:00
I'm newbie. I try to execute your code, but it always said Runtime Error: "SetVector2 - Matrix does not exist". I dunno why.
Dark Gamers
16
Years of Service
User Offline
Joined: 17th Mar 2008
Location:
Posted: 19th Jul 2008 18:12
Sorry, It's my fault. I forget to add:

dbMakeVector2(1);
dbMakeVector2(2);
Dark Gamers
16
Years of Service
User Offline
Joined: 17th Mar 2008
Location:
Posted: 19th Jul 2008 19:17
you can add an if statement to stop the moving:

bool move = false;
int xx = 0;
int zz = 0;

void DarkGDK ( void ){ while ( LoopGDK ( ) ){

if(dbMouseClick()) {
//get the 3d position of mouse clickingg place
xx = xHit;
zz = zHit;
}

if(move) {
//get the current position of object
int x = dbObjectPositionX(3);
int z = dbObjectPositionZ(3);

//once the object at the mouse click place, stop move
if(xx==x && zz==z) {
move = false;
}
}

}//end while
}//end darkgdk

Login to post a reply

Server time is: 2024-11-17 20:59:52
Your offset time is: 2024-11-17 20:59:52