V
V
vaselekk2020-11-23 20:35:56
Mathematics
vaselekk, 2020-11-23 20:35:56

How to calculate mathematical degrees?

5fbbf1f84427c553931568.png

Hello people. I'm making a simple game, in which you need to make sure that the tower object always turns towards the player, in this picture: A is the tower object itself, and (B) is the player.

They are at the position (x, y) = A(100, 100), B (200, 200)

So in the photo you can presumably say that the tower should be rotated 135 degrees.

I did the calculations (the formula is visible in the picture) I got 0 in the results, PLEASE TELL ME WHERE I made a mistake? even when I tried to make such values ​​so that there was no zero in arctg, it still showed incorrect degrees.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mercury13, 2020-11-23
@Mercury13

And the arc tangent must be taken arctan((200−100)/(200−100))
In addition, for this there is a function atan2, defined for all x and y that are not equal to 0 at the same time.

D
Dmitry Gordinskiy, 2020-11-23
@DmitriyGordinskiy

Wrong coordinates in the formula substituted.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question