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.

2D All the way! / Getting a sprite to move directly to the mouse.

Author
Message
77!M
19
Years of Service
User Offline
Joined: 26th Mar 2007
Location:
Posted: 27th Mar 2007 02:28
Basically, when you click the mouse the sprite needs to 'walk' to where the mouse has been clicked. I can only get the sprite to move along the horizontal/virtical/diagonal axis which is close to what I want, but not quite. I would prefer it if the sprite would go directly to the mouse, whatever angle it is.
Here is my code.



Sorry that it's a little messy, I'm just testing out possibilities.

Any suggestions would be ideal. I'm making a really basic top-down RPG. Oh, and I'm using DarkBASIC PRO.
(I had a quick scan of a few pages on the forum and couldnt see anything that helped, so I'd appreciate any ideas or thoughts)

Thanks
-Will
aluseus GOD
19
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 27th Mar 2007 05:38
Simple...
Make an algorithm with trigonometry to find the angle, then use this code snippet...

(horizontal speed variable) = sin(angle)
(vertical speed variable) = -cos(angle)

If you're patient, I'll give you the code...
77!M
19
Years of Service
User Offline
Joined: 26th Mar 2007
Location:
Posted: 27th Mar 2007 15:30
Sounds good.. only my maths.. well, the less said about it the better. I would definatly appreciate it if you could provide the code as I havn't a clue with trigonometry.
aluseus GOD
19
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 27th Mar 2007 18:57
Working on it right now. I have some glitch where division by 0 occurs, so I have to fix that first...
Dave1974
21
Years of Service
User Offline
Joined: 1st Aug 2004
Location:
Posted: 28th Mar 2007 00:20
Hi Guys.

I will need this for my own program, so I came up with this.



Hope this helps.
77!M
19
Years of Service
User Offline
Joined: 26th Mar 2007
Location:
Posted: 28th Mar 2007 01:18
Ah thats sweet! Thank you very much

Thanks also aluseus GOD for any effort you put in, shame the other chap got there first eh!

-Will
aluseus GOD
19
Years of Service
User Offline
Joined: 19th Mar 2007
Location: I\'m here. Now I\'m there. I keep moving
Posted: 28th Mar 2007 06:12
It's okay. I gave up after it kept messing up with a variety of unsolvable problems...
Yeah. I'm testing his, see what it does, cause I need this too!

Login to post a reply

Server time is: 2026-07-05 02:42:05
Your offset time is: 2026-07-05 02:42:05