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.

Newcomers DBPro Corner / Sprite not moving correctly

Author
Message
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 7th Aug 2012 18:29
Hey there.

Could somebody please help me fix this code?
The idea is for the sprite to rotate to the mouse and move towards it. Everything works, except for the sprite to move perpendicular to the mouse.

Here are the images used in the project:

gra_bkg.jpg



guy.png



cursor.png






Anybody ?

Follow me on twitter! @MotionStruct
Motion Struct blog
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 8th Aug 2012 13:58
Quote: " Everything works, except for the sprite to move perpendicular to the mouse."

You'll probably need to 'offset' the angle by 90 degrees.

Try either this:



or



Note the +- 90.0 to the value returned by atanfull.

29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 8th Aug 2012 20:35
Hodgey is right and I can confirm that it's the second suggestion, ie +90



I've replaced the code where your loading images with just some boxes and modified the "angle" equation to add 90 degrees so you can just run the code.
kamac
13
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 9th Aug 2012 14:17
Thanks, everything's fine now.

Follow me on twitter! @MotionStruct
Motion Struct blog

Login to post a reply

Server time is: 2024-11-21 23:25:46
Your offset time is: 2024-11-21 23:25:46