forums

TNT Basic Forums > Programming Q&A
Angles
< Last Thread     Next Thread >
Author
Thread        Post A Reply

01-13-2003 00:49

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

I am making a game where sprites moving using degrees.

I want one of the sprite to run after the other.

How can I calculate the angle ( the direction the sprite must go ) between those two sprites ?

01-13-2003 22:48

Posted by:
Holmes

Location:
Santa Rosa, Ca

Click Here to Email Holmes   Find more posts by Holmes

Got you covered

I wrote a procedure that does just this when making my game, Raptor.

The function takes the x and y coordinates of the object that needs to point somewhere, as well as the x and y coordinates of where it needs to point. The function returns the value (in degrees) that the sprite needs to rotate to point at the point.

Procedure rotateturret(int aimerX,int aimerY,int targetX,int targetY)
float angle=invtan((targetY-aimerY)/(targetX-aimerX))
end Proc (angle)

If we remember our trig:

The tangent of an angle is equal to the length oposite side (height) over the length of the adjacent side (width). The length and width of these sides can be found by getting the difference in X and Y of the two points. Since we know the lengths of the sides, and not the angle, we'll use inverse tangent on this to find the angle. Simple (sort of), but powerful.

01-13-2003 23:59

Posted by:
matteo

Location:
Venice, ITALY!

Click Here to Email matteo   Find more posts by matteo

hmmm...

The problem is invtan gives only values from -90 to 90. You should use something as angle=angle +180 if targety>aimery or the other way round.
Anyway, from where does this angle start and in what sense? You must check that, it' s too difficult to figure it out theorically...
And if targety=aimery, wanna getta crash?

01-14-2003 01:37

Posted by:
Toast

Click Here to Email Toast   Find more posts by Toast

Angle is here

the URL for the Angle source code is here:

http://ellrx.250free.com/angles.sit

and you can thank eLL for it.

01-14-2003 03:33

Posted by:
eLL

Click Here to Email eLL   Find more posts by eLL

THANK DAN LAB



yeah i'm hosting it,but danLab built it...he has far more time

(all i have is from 8-10 am and 9pm-1am, i am the night...i am Bat-* sorry one too many toonami boomeraction shows)

tools( poor college student) and dedication(girls, girls, girls, girls i do adore) to this stuff than i do.

DanLab publishes a new high qual game every one to two months that's faster than most small console developers.

rambling...give DanLab a round of a applause, eh ??

01-14-2003 23:14

Posted by:
someone

Location:
Quebec ( Canada )

Click Here to Email someone   Find more posts by someone

Thanks A LOT, guys :) !

01-15-2003 14:56

Posted by:
Holmes

Location:
Santa Rosa, Ca

Click Here to Email Holmes   Find more posts by Holmes

No no.

if targety = aimery there is no problem. However, it is a divide by zero error if targetx = aimerx. The program, however, will NOT crash. Trust me, I've used this in Raptor and 30,000 people seem to not have that problem.

You're probably right about the -90 to 90 thing though. I'm sure my original code worked (and it incorporated the what you talked about) then I changed my code at the last second to make it simpler. I checked it and it seemed to work, but maybe it doesn't.

01-15-2003 21:16

Posted by:
Mark Tully

Location:
TNT HQ, England

Click Here to Email Mark Tully   Find more posts by Mark Tully

Wow!

30,000 users?! No bad!

Mark

01-16-2003 02:44

Posted by:
Holmes

Location:
Santa Rosa, Ca

Click Here to Email Holmes   Find more posts by Holmes

Hehe, I make it seem as if I consider them popcorn :)

Really, I'm quite amazed at this figure too since this is my first (released) game. Sort of makes me think about what it would have been like if I had charged $$

Oh well, tis a very noble cause freeware is! Indeed a noble cause!

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.