Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Follow the crosshair
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
SaintK




PostPosted: Mon Dec 07, 2009 9:08 am   Post subject: Follow the crosshair

Simply said im trying to ge a character to look towards the crosshair (mouse position) in the game im creating with some friends so my question is..

How would I manage to make it so that my little character dood, say a little triangle (no the game is not asteroids), look at the mouse position with fluency rather then just the 8 positions of the compass?
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Mon Dec 07, 2009 9:22 am   Post subject: RE:Follow the crosshair

You need to determine the angle from your character to the mouse cursor. From there, you can use Pic.Rotate() or similar to draw your character.

The easiest way to determine the angle is the following:
code:

var dx : real := mouse_x - character_x
var dy : real := mouse_y - character_y

% tan (angle) = opposite over adjacent = dy over dx
% angle = tan-inverse ( dy / dx )
var angle : real := arctand ( dy/dx )

put angle
SaintK




PostPosted: Tue Dec 08, 2009 8:42 am   Post subject: Re: Follow the crosshair

alright thx for the help
mirhagk




PostPosted: Tue Dec 08, 2009 10:40 am   Post subject: RE:Follow the crosshair

you can even use that code with a pic file to rotate the picture to face the cursor (like have one pic for character's body and one for his head, and his head rotates to follow the cursor)
SaintK




PostPosted: Wed Dec 09, 2009 9:12 am   Post subject: Re: Follow the crosshair

>.< this may be too much for me as doesnt character rotation require math? and math isnt exactly my "area of expertise" so what im asking is for a simpler description of character rotation with the mouse, unless there is a tutorial out there that I have not found.
mirhagk




PostPosted: Wed Dec 09, 2009 9:24 am   Post subject: RE:Follow the crosshair

You really can't get much simpler. You certainly cannot calculate the angle without math lol. In order to succeed in programming you need to know math, including trigonometry.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: