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 / Moving an object to the coord of the mouse cursor

Author
Message
Drowneath
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location: In your eyes
Posted: 22nd Jun 2009 18:10
Hello there,

I'm trying to create a simple RPG game (learning purposes)

But I'm having trouble on moving the player to the coordinate selected by a mouse click.

Well, just to find out if my code works or not, I tried to generate a cube to the mouse's selected area.
But...





Any kind of help would be appreciated
jezza
16
Years of Service
User Offline
Joined: 8th Mar 2008
Location: Bham, UK
Posted: 22nd Jun 2009 20:06
the mouse's X Y and Z position are in screen space, not 3d space. the z value also refers to the scroll wheel.

use this function:
void dbPickScreen ( int iX, int iY, float fDistance )

using dbMouseX and dbMouseY for x and y, and however far you want the object from the camera as distance.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 22nd Jun 2009 20:57
Have a look at this thread, it seems to be the same problem.

http://forum.thegamecreators.com/?m=forum_view&t=152343&b=22
Drowneath
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location: In your eyes
Posted: 23rd Jun 2009 03:02 Edited at: 23rd Jun 2009 15:06
Well, it ALMOST worked.
But the objectZ seems doesn't change at all.
So it position my object incorrectly.

However, I don't understand what the code did with the math :S





Well, I think this is a different problem.
From the link you given, the object will only follow the mouse's x and y coordinates and ignoring the distance from the camera to the pointed area (z coords).
Drowneath
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location: In your eyes
Posted: 23rd Jun 2009 13:47
I think this is a different problem.

From the link you given, the object will only follow the mouse by the mouse's x and y coordinate, but not the z coordinate of the pointed area (distance from the camera to the pointed area).
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 25th Jun 2009 09:22
Sorry, I haven't looked at the forum for two days and even now only for 5 minutes before going to work.
I have another code which moves the object in the X/Z plane instead of X/Y. I can show that to you but then the problem will be that it does not take terrain height into account.
Looking at your screenshot and what you want to achieve, my next idea would be to implement some raycasting and determine at which point the "ray from the mouse" collides with the terrain. But I have not much idea how to do that. I remember there is a demo in Sparky's collision system which shows "shooting" at objects with the mouse but that finds objects, not terrain, and I don't know if it would work with terrain.
Maybe somebody else can help you more, or I try to find a better solution when I have a bit more time (maybe in the week-end).
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 25th Jun 2009 23:45 Edited at: 25th Jun 2009 23:55
Somebody on this forum recently pointed to a nice site: http://zimnox.com/dbcc/?page=tutorials

There is an RTS tutorial here which may be interesting for you. Although it is for Dark Basic, the code is easy to convert to Dark GDK. The tutorial suggests this code:



Substitute IDTERRAIN and IDCUBE with the ID numbers of your objects. There may be other solutions (if other forum members know a better way, please correct me) but this is easy and it worked when I tried it on a sample terrain.
Drowneath
15
Years of Service
User Offline
Joined: 22nd Jun 2009
Location: In your eyes
Posted: 26th Jun 2009 19:15
Thanks a lot, Mireben!

It worked like a magic ;D

Login to post a reply

Server time is: 2024-10-01 05:58:25
Your offset time is: 2024-10-01 05:58:25