forums

TNT Basic Forums > Programming Q&A
Angle of one point to another...?
< Last Thread     Next Thread >
Author
Thread        Post A Reply

05-19-2003 20:16

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

How can I find out what angle a second point is to the first.

I'm making a vector based Asteroids type clone with many enhancements and I'd like to add weapons that follow an object.

The best way I can think to do this is have the Heat Seaking Missile get the angle of theobject it is chasing relative to its current location and change the heading that way.

I can do this if I just knew how I could find the angle of a point to another one.

Maybe a routine I can call like:
Angle = FindAngle(50,50, 366,164)

Anyone know how to do this? I've already mastered the Sin and Cos functions in 6 hours (Something I didn't even understand before last night), I just need this one cool feature for now.

05-19-2003 23:09

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

angle=invtan((y2-y1)/(x2-x1))

05-19-2003 23:26

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

Thanks, Dan! It seems to work, I will know for sure once I get the Heat Seaking Missiles implimented.

Another question, how about finding out if one point is within a certain distance from another?

Like for instance, an example.

If the Missile's X and Y points are within the radius of the asteroid you're aiming at?

Say a radius of 20 pixels... Like if the asteroid had a radius of 20 pixels and Want to know if the missile intersects with this area.

I completely forgot about that ability. Without that my game will have all square rocks. That will suck. I need radius. Thanks in advance.

05-20-2003 01:29

Posted by:
MapMaker

Location:
Edmonton, Alberta (Canada)

Click Here to Email MapMaker   Find more posts by MapMaker

Radius not needed

For something like that, I'd just use Sprite Col.

05-20-2003 02:36

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

No. I need mathematical calculations for a radius. I am not using sprites at all at this stage. I need a function to do this.

And I also need a function to calculate how far apart two pixels are. In other words, you have a line, figure out how long the line is. Since it will be at any angle, it's not as simple as subtracting point 1 from point 2.

I'm stuck and at a loss until I get these two functions. I know they're possible. I just don't know how.

05-20-2003 21:33

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

1- Look in "Circle wall" topic.
2- I *think* the distance is : width*width+height*height = distance*distance so you can use a square root : squrt(width*width+height*height)

Width is the difference between x and x2 and hieght the difference between y and y2

05-21-2003 11:44

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

Distance between points can be done with the Pythagorean theorem.

Distance = sqrt((x2-x1)^2+(y2-y1)^2).

As someone mentioned elsewhere, if you don't care what the real distance is, and just want to know if they are closer than some distance together, you can do this:

rsquared=r^2 'Where r is the radius of your object.

Then just check

if ((x2-x1)^2+(y2-y1)^2)) <= rsquared

If this is true, then the second point is inside the radius. This is faster, since the first version requires a square root, which is slower.

05-21-2003 12:07

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

but pay attention it the points are moving close to the speed of light...

05-22-2003 11:27

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

I'm not sure how many people will enjoy a game of Asteroids where the objects are moving at near-light speeds. Most people don't have that kind of reflexes.

05-22-2003 15:18

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

i wonder if it would be possible to make a game where things moved at the speed of light or faster?

05-22-2003 21:41

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I don't know what you mean exactly by "speed of light", but YOU control the speed of the sprite.

05-22-2003 22:22

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

when i say the speed of light, i mean the speed of light, which is what, 300,000 Km/second. anyway, it was just a passing thought.

05-24-2003 02:06

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

LOL. I don't think a little ship would even have a chance against a rock moving the speed of light. I won't be using speeds quite THAT fast. ;-)

05-24-2003 03:36

Posted by:
DanLurie

Location:
Earth>USA>New Jersey>Clifton>My Chair

Click Here to Email DanLurie   Find more posts by DanLurie

Well, a monitor does project light, so technically all computer games move at light speed. Not to encourage that guy, though.

05-24-2003 05:49

Posted by:
puffin

Click Here to Email puffin   Find more posts by puffin

i don't want to start another one of these discussions, but the speed at which a game moves depends on what you mean by the word game.

05-24-2003 14:03

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Do you realise how fast 300000 km/s is? You wouldn't even see the sprite on the screen!!!

05-24-2003 17:02

Posted by:
Jason Anderson

Location:
Doylestown, PA

Click Here to Email Jason Anderson   Find more posts by Jason Anderson

Guys, don't worry. I think Matteo was kidding about the whole light speed thing. Telling me to pay attention if any of my enemies move that fast. It was a joke. There will be no enemies moving quite that fast in this game.

All times are GMT        Post A Reply

Forum Jump:
< Last Thread     Next Thread >

< Contact Us - TNT Basic >

Powered by: vBulletin Lite Version 1.0.1 Lite
Copyright © Jelsoft Enterprises Limited 2000.