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! / angle between two points

Author
Message
G T R
21
Years of Service
User Offline
Joined: 26th Apr 2005
Location: Dubai, UAE
Posted: 25th Apr 2006 05:57 Edited at: 25th Apr 2006 06:01
I searched all the help files in dpp and couldn't find it!
i want to calculte the angle between two points
i made this function but it didnt work:

its a 3d game i made i want the enemy to look at the
hero so i passed the following variables:
x1 = x position of the hero
y1 = z position of the hero
x2 = x position of the enemy
y2 = y position of the enemy

and it gave me a constant value

any ideas??

<edit>
does this method work if one or more of the values is less
than 0?????
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 25th Apr 2006 06:42 Edited at: 25th Apr 2006 06:42
I believe it's this:

angle# = atanfull(x2#-x1#, y2#-y1#)

Tempest - P2P UDP Multiplayer Plugin (DBP/DBCe) - 71%
Download the free version
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 25th Apr 2006 10:36
Wrong forum.

G T R
21
Years of Service
User Offline
Joined: 26th Apr 2005
Location: Dubai, UAE
Posted: 25th Apr 2006 12:04
Benjamin
Thx Benjamin it worker

Pincho Paxton
well i put it here cuz its a 2d math
SirFire
21
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 26th Apr 2006 05:23
Correct me if I'm wrong, but don't you need 3 points to determine an angle? 2 points is only a line, which has no angle.

Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 26th Apr 2006 06:27
Of course a line has an angle. A line's angle is the angle between the first and second point.

Tempest - P2P UDP Multiplayer Plugin (DBP/DBCe) - 71%
Download the free version
SirFire
21
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 26th Apr 2006 13:57
nop

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 26th Apr 2006 22:57
The angle of a line is the angle with the horizontal x-axis. Which is:
y = 0

2 ways to calc it:
1:
use trigometry:
alpha = atan((y2-y1)/(x2-x1))
( tan(alpha)*(x2-x1)=(y2-y1) )

2:
use DBP's own atanfull like Benjamin.

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
SirFire
21
Years of Service
User Offline
Joined: 4th Apr 2005
Location: North America
Posted: 27th Apr 2006 02:50
Yes. That is correct, now you have a third point to reference.

You get a gold star.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 27th Apr 2006 04:43
Quote: "I believe it's this:

angle# = atanfull(x2#-x1#, y2#-y1#)"


Sounds correct to me.


Login to post a reply

Server time is: 2026-07-04 15:04:18
Your offset time is: 2026-07-04 15:04:18