Author |
Message |
SaintK
|
Posted: 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? |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
Posted: 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
|
|
|
|
|
|
![](images/spacer.gif) |
SaintK
|
Posted: Tue Dec 08, 2009 8:42 am Post subject: Re: Follow the crosshair |
|
|
alright thx for the help |
|
|
|
|
![](images/spacer.gif) |
mirhagk
|
Posted: 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) |
|
|
|
|
![](images/spacer.gif) |
SaintK
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
mirhagk
|
Posted: 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. |
|
|
|
|
![](images/spacer.gif) |
|