Can someone explain this (ToDeg(atan2

Can someone explain this (ToDeg(atan2…
:slight_smile:
is there some explanation, (link)

I was looking/experimenting with one game example ( Basic ai with pathfinding, its the one where green tanks case you)

I was curious myself. I created a little project to test it. You can drag the IA object.
The formula gets the angle toward perso which I assume is the player, it then casts a ray from the IA in that direction at a distance of 600px. If there’s a “Solid” object between that point and the IA then it saves the x and y in variables and triggers the sub events.

It’s basically checking if there’s an obstacle blocking the IA’s view of the player and allowing the IA to only see a certain distance away.

This might explain it better. The circle represents the point that the formula finds. I reduced the distance. If there’s a “solid” in between the circle and the IA, it puts an “X” object at that position.

To add onto what Keith said, atan is the arc tangent, a common function used in high school trigonometry. atan2 is a common extension of the atan function present in many programming languages, which allow to do trigonometrical operations while handling special edge cases, to measure an angle a line from 0;0 to x;y would have.

The ToDeg is because trigonometrical functions, e.g. sin/cos/tan, work in radians, but GDevelop uses degrees, so those must be converted using this expression.

This is an old example, nowadays, you would do ˋIA.AngleToObject(Perso)ˋ (or whatever this expression is called)

2 Likes

thank you

I have one more problem,…
if I set max distance for 111 it doesn’t change back variable to 0
only if distance is for example 1111 then it changes it back to 0
(same picture)

The 2nd cast a ray is set to 11 pixels while the 1st is 111. I’m not sure what your goal is but I’m wondering if they both should be the same. Also, 11 pixels is pretty close The objects would be almost touching each other.