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 a mouse click location

Author
Message
jontepd
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: Sweden
Posted: 5th Mar 2009 16:30 Edited at: 5th Mar 2009 18:22
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.

Attachments

Login to view attachments
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Mar 2009 18:58
... Your code ...


Question: Assume your target is 0.1 units away, when will the objects y position ever be able to equal the target y position?

Answer: Never. The first movement will move the object too far.

The fix is to check the distance between the object and the target. If the distance is less than your movement rate, simply move the object to the target position and stop moving.

jontepd
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: Sweden
Posted: 5th Mar 2009 20:23
Then this should work, right?


But it doesn't...
jontepd
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: Sweden
Posted: 6th Mar 2009 20:32
I've tried fiddling a little with the code with no real result. However i noticed that the tank stops moving, but it stops moving at the wrong location. If i press a little above the tank it will move more than it is supposed to, if i try to click a little below the tank it will move even further...I have no idea what i'm doing wrong.

jontepd
15
Years of Service
User Offline
Joined: 24th Feb 2009
Location: Sweden
Posted: 6th Mar 2009 21:30
I tried putting in a text message at the object's y location (dbObjectLocationY), and as default it always posts the message at the top of the screen even when the object isn't there. If i do the same thing with the objects X location it posts the message at the end of the screen (to the left) as default, why is this?

Login to post a reply

Server time is: 2024-09-30 19:17:54
Your offset time is: 2024-09-30 19:17:54