Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

2D All the way! / Sprite angles

Author
Message
Khumba
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 5th Apr 2003 03:39
Hello, I'm making a top-down view RTS game, and I'm going to make the ships rotate (and point to where they're going to, obviously). However, since I'm using sprites not models, I don't know what the algorithm is to calculate the angle. Take this example: (X is the unit, Y is it's destination)
X


Y
It's obvious it has to point southeast, but how can I figure out what exact angle? Eg. maybe a function that you give an X&Y offset of the target from the source and returns the angle. Any help is appreciated. Thx!
andrew11
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 5th Apr 2003 06:12
It took me a while, but I figured it out. This function will point any sprite to any point you specify. It will only work for DBPro because of the rotate sprite command.



The "atan" command is not very accurate so the sprite is not always exactly pointed the right direction (I'm trying to fix that).

Heres a demo:



All programmers are playwrights and all computers are lousy actors." -Anon.
<--- Uh... Um... Oh I forgot
Khumba
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 5th Apr 2003 18:30
Ok, thx! I'm putting it into my code now, I had a little problem because I was using offset sprite() and that still rotates around the unoffsetted (is that a word?) center.
Khumba
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 5th Apr 2003 18:41
(Oh, and on my first post, I told it to put a ton of spaces before the Y.)
andrew11
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 5th Apr 2003 19:29 Edited at: 5th Apr 2003 19:30
Yeah, this forum deletes spaces before words.


You could use [Center]

Y

X

All programmers are playwrights and all computers are lousy actors." -Anon.
<--- Uh... Um... Oh I forgot
Khumba
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location:
Posted: 5th Apr 2003 22:47
Oh, ok, thx. One way to make it more accurate is to change (in the example) x and y to x# and y#.
andrew11
21
Years of Service
User Offline
Joined: 23rd Feb 2003
Location: United States
Posted: 5th Apr 2003 23:02
Oh, I just noticed a mistake.
Heres the correct code:



All programmers are playwrights and all computers are lousy actors." -Anon.
<--- Uh... Um... Oh I forgot

Login to post a reply

Server time is: 2024-04-26 17:35:26
Your offset time is: 2024-04-26 17:35:26