
-----------------------------------
SaintK
Mon Dec 07, 2009 9:08 am

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?

-----------------------------------
DemonWasp
Mon Dec 07, 2009 9:22 am

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
[/code]

-----------------------------------
SaintK
Tue Dec 08, 2009 8:42 am

Re: Follow the crosshair
-----------------------------------
alright thx for the help

-----------------------------------
mirhagk
Tue Dec 08, 2009 10:40 am

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
Wed Dec 09, 2009 9:12 am

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
Wed Dec 09, 2009 9:24 am

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.
