http://GameProgrammer.Com

Programming

GP Mailing List
     Thread Index
     Date Index

ATXGPSIG List
     Thread Index
     Date Index

Google
>

Home

Wise2Food



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Turning to face a direction



============================================================
"Before myTopica, I was buried in an avalanche of email.
Now, thanks to this free solution, I am on top of my inbox."
Get rescued at
http://click.topica.com/aaabBBbUrGczbU68iFa/register
============================================================

Hi Paul,

	Thanks, I managed to get it working using your example. Maths never was my
strong point, never saw the point in trig... now I do :-( well time to get
out the GSCE books and revise I think.

Thanks,

	Tom.

-----Original Message-----
From: probson@powerup.com.au [mailto:probson@powerup.com.au]
Sent: 23 March 2001 14:13
To: gameprogrammer@topica.com
Subject: RE: Turning to face a direction


============================================================
A personal trainer for your email inbox, My Topica's  free
newsletter management system provides total email
conditioning thru archives, organizers, and options.
http://click.topica.com/aaabDlbUrGczbU6XPca/register
============================================================

Hi Tom,

You can figure out the exact angle that you need to turn using basic trig.

if the player is at position (x1, y1) and the destination is (x2, y2) then
the appropriate angle is

theta = atan((y2 - y1) / (x2 - x1))

then you'll have to convert that from radians into your system of angles ...
which is 32nds of a circle right?  so that means you go

theta = theta / 6.283185307179586476925286766559 * 32

and then you'll have your answer.  you might have to adjust it to make it
work correctly for your coordinate system.  And if that doesn't work,
then... I'm sorry :)  it's late in the great down under.  you might have to
recalculate periodically too to make sure that you're going on the best
angle to get you to your destination, but you prolly do that every frame
anyway so that's alright..

Oh, also, that's assuming that atan = inverse tan.  I think it is...

Paul


Tom Webb wrote:

============================================================
"So many interesting emails. So little time to read them.
Thanks to myTopica, I can find what I want, when I want it."
So can you.
http://click.topica.com/aaabBCbUrGczbU6XN9a/register
============================================================

Hi,

	I have the code working for turning a ship around and flying manually but
what I really want is for my ship to be able to fly on autopilot. So if I
give it a destination X and Y it will slowly (1 in 10 module iterations)
turn to face the direction and fly there.

	I have 36 different directions my ship can face and that is all working
fine, I am just having a touch of difficulty with the logic.

	Any ideas? :-)

Tom.

------------------------------------------------------------
Join "Hot Sauce" newsletter at: www.pepperbob.com
The "best" FREE samples,FREE offers and CONTESTS 3x a week!
<A HREF="http://www.pepperbob.com">CLICK HERE</A> to Join!

____________________________________________________________
T O P I C A  -- Learn More. Surf Less.
Newsletters, Tips and Discussions on Topics You Choose.
http://www.topica.com/partner/tag01


------------------------------------------------------------
Join "The Six Figure Income Safelist" NOW! Absolutely FREE!
Plus receive 3 FREE E-Book downloads for subscribing.
http://www.topica.com/lists/sfisafelist/

____________________________________________________________
T O P I C A  -- Learn More. Surf Less.
Newsletters, Tips and Discussions on Topics You Choose.
http://www.topica.com/partner/tag01

------------------------------------------------------------
Join "The Six Figure Income Safelist" NOW! Absolutely FREE!
Plus receive 3 FREE E-Book downloads for subscribing.
http://www.topica.com/lists/sfisafelist/

____________________________________________________________
T O P I C A  -- Learn More. Surf Less. 
Newsletters, Tips and Discussions on Topics You Choose.
http://www.topica.com/partner/tag01