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 / How can i get a sprite to turn towards the mouse?

Author
Message
Game Master1330
17
Years of Service
User Offline
Joined: 19th Oct 2007
Location: (GetReaderXYZ() * 42 ) / 0
Posted: 20th Sep 2010 22:29
I am making a spacship game, and the ship constantly moves forward, but i want it to always face the mouse.

Any help much appriciated =D

Matt

Umm...
Dodga
14
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 20th Sep 2010 23:00
This should help explain it, you have to use either trig, or a vector.

http://www.albinoblacksheep.com/flash/trig
Game Master1330
17
Years of Service
User Offline
Joined: 19th Oct 2007
Location: (GetReaderXYZ() * 42 ) / 0
Posted: 21st Sep 2010 00:55
Thanks but im stumped.

y is 512
x is 300

tan(theta) = y/x

how can i work out theta in darkbasic?

trig is so confusing <_<

Matt

Umm...
Game Master1330
17
Years of Service
User Offline
Joined: 19th Oct 2007
Location: (GetReaderXYZ() * 42 ) / 0
Posted: 21st Sep 2010 00:57
oh wait
i just realized db supports sin cos tan lolz

Umm...
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 23rd Sep 2010 06:53
Basically, you have all these values:
sprite_position_x
sprite_position_y
mousex()
mousey()
sprite_current_angle

What you want to do is this:
sprite_new_angle=atanfull(mousex()-sprite_position_x,mouey()-sprite_position_y)

Then you'll want to step a small distance from sprite_current_angle to sprite_new_angle, so that it looks like the sprite is turning slowly (theres a dbpro command that does that)

Login to post a reply

Server time is: 2024-11-23 07:32:47
Your offset time is: 2024-11-23 07:32:47