# Thread: need help understanding atan2?

1. ## need help understanding atan2?

Atan2(Y2-Y1,X1-X2)

i read a tutorial on the net, it says the formula is instead=
http://www.gamefromscratch.com/post/...e-a-point.aspx
(Atan2(Y2-Y1, X2-X1)) * (180/Pi)

lol?

I am very confused. I also tried reading on it, but its beyond me my knowledge of math is basic. But if someone could try to explain to me the steps of what this does id appreciate it...

Y2-Y1 retrieves the space of distance found between the two points... i know dis much...

also, how can I control my x and y movement in relation to my currecntly facing angle (like forward facing this angle? how do i add x and y in relation to this?)

2. (Atan2(Y2-Y1, X2-X1)) * (180/Pi)

this would convert the angle degrees in radians, but you'll likely don't need it

Atan2(Y2-Y1,X1-X2)
calculates the angle of a vector joining XY1 and XY2
so you can use it to determine which angle your object must face o "look at" a specific target position
X,Y terms are inverted because in computers we have by default Y positions going downward,
differently from pen-and-paper Cartesian plane where they go upward

i.e.

Atan2(Ytarget-Yplayer,Xplayer-Xtarget)

you can use builtin OAngle("player",Xtarget,Ytarget) function for this as well,
is very slightly faster, but will give you integer result - less precision.

to move in direction of your angle,
simply use sin and cos:

>>> add cos(angle) * speed to Xpos
>>> sub sin(angle) * speed to Ypos
>>> set X position to Xpos
>>> set Y position to Ypos

use above additional step with "Xpos,Ypos" values because sin/cos will give floating point results
and Fusion does not support this in raw X,Y positions (but support them in values)

3. Schrodinger,

Just saying, I would personally pay for this, but what about a Schrodinger Udemy Fusion Math Course for Dummies? Lol. A variety of different functions that do different stuff in Clickteam with a breakdown.

I know your super busy altering 2d reality into 3d, , but I know this would help everyone so much get the most out of fusion and the event editor!

4. I'm all in for "Schrodinger Udemy Fusion Math Course for Dummies"!
Seriously speaking, I'm still in.

5. I'm 100% in, too.
A Schrodinger Udemy course for math/trigonometry would definitely be beneficial to the whole community

6. Aahahaha
no guys I'm not that good actually,
just learnt what I needed over the time by studying around.
Internet is full of much more brilliant and extensive resources on the subject than myself.

For games (2D games ) you'll mostly need just a bit of trigonometry actually.

Of course I'm available for any question I'm able to answer!

I was thinking dedicating a page in my website
(once I got some time to actually make it look like a website..)
to most useful expressions for gaming
so that could be used as a quick reference when needed.

But would be just a repository for most useful/frequently used expressions.

7. what does cosine do? and sine? does it return the difference of the current angle or something?

8. you can see sin (blue) and cos (red) in this picture:

will give you the horizontal and vertical component of the vector
going from origin (i.e. your player position)
basing on its angle

9. hmmm, I almost understand now a bit.
very interesting.

10. If schrodinger isn't interested, I could consider teaching a Udemy course in simple Fusion concepts if enough people were interested to make it worth the while (somehow I doubt it though as it's all stuff you can learn on your own). As far as math goes, schrodinger is right --- for 2D games, you'll generally just need an understanding of high-school trigonometry. Look up SOHCAHTOA for an easy way to understand how sin, cos, and tan relate to the sides of a right triangle.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•