# Angle to Position cant go past 180º, is that normal?

I was struggling to properly animate my top down enemies with dynamic 4 directional movement (not trying to sound smart, i just dont know how to describe it better )…

When suddenly i had the genius idea of simply using angles, and it works!!!

…but while i was figuring stuff out, i foud out that “AngleToPosition” didnt go to 360º, instead it goes between -180 to +180.

The reference 0º being directly to the Left of the object, which is odd to me as well, since i thought 0º in GDevelop was to the Right of the Object, kinda like how RayCast works. (or am i mixing that up?)

Before putting my idea into practice i decided to see the actual values of “AngleToPosition”, so i made a Text object displaying a variable that was constantly being updated with “AngleToPosition”, between my player character and the closest enemy, thats when i saw it.

the values go something like…
90º
180º
-90º

…positive degrees go above the Object and negative degrees go bellow the Object.

So, is that normal? …im mostly just curious

Just came across this. All you need to do is add 180 to it.

like this:

huh?

But now you start at 180º not at natural 0º which wont work since its no longer accurate.

This is how I work with angles in GDevelop, I always had problems with 360 deg:

1 Like

Thats how it usually works, for example Raycasting uses that angle scheme.

But AngleToPosition is backwards, the 0º is on the Left side and negarives are below, thats why i started this post to begin with, i thought it was really odd.

Usually when calculating an angle between 2 positions, it’s calculated from the main object to the target object. I’ll try to make sense of this!

Let’s say Player and Enemy are on the same Y position.
If you’re using Player.AngleToObject(Enemy)
The angle is calculated from Player (main) to the Enemy (target).

If Player is on the left, then the angle would be 0.
If Player is on the right, then the angle would be 180 / -180.

Same thing with the other expressions:

• Player.AngleToPosition(Enemy.X(),Enemy.Y())
• AngleBetweenPositions(Player.X(),Player.Y(),Enemy.X(),Enemy.Y())

So if the main object is on the right of the target object, then the calculated angles would be flipped. Let me know if this makes sense at all!

1 Like

This is sometin pested me in old days…
if you try to rotate to 180 a sprite you gonna notice a flip for a millisecond…(i don’t have the tima but maybe you could try to search my old angle threads)
I spent a whole year ( no joke) to adapt that issue to my game…and while i solved with Object.points Left and right it is something still noticable…
You can’t do much about it…it is just a bad way to handle angles…it’s there from day one.

even the famous +180 trick will not solve much

1 Like

It does, thats pretty cool!

I was merely curious when i saw the angles changing and started getting values i wasent expecting.

I actually made a text on screen showing the angle to enemies as i was walking around them, but despite what you just said, which would make sense, i never saw 0 on the right, even when approaching enemies from the right, at least not that i remember.

1 Like

If you notice on this video, i mostly approach enemies from the Left, and the angle 0º is on the left, but at 3:07 i approach an enemy from the Right, and the 0º is still on the left.

There isnt any actual issue, this quirk isnt stopping me from doing anything, i was just wondering how it worked since i was under the impression that 0º was on the Right, like Raycast and not on the left.

I don’t see anything wrong with the numbers in the video, even after 3:07 when the enemy starts following. Since you’re calculating the angle with the player being the main point of reference, then the numbers are like this:

1 Like

this may be Ot since biscuit solved his problem but
that bug (or bad choice) is simple to check.
create an object like this:

stick this to a position, then point the yellow to whatever you want, mouse pos or rotate action. (i’m using my right analog stick) When it reach 180 you gonna notice a flip for a millisecond…thaz probably bcs signs overlaps.,(noone cared…sadly)
…as i said above this pested me for a whole year.
but it’s there …as many other things…in the video it seems to work fine bcs the sprite/player does’nt rotate but flip.

Mate i really appreciate the effort but thats backwards, unless your seeing something im not, which wouldnt be surprising but…

the 0º is clearly on the Left and the 180º on the Right. which was what i found odd to begin with

as far as i know insein is right about how gd handle angles

2 Likes

OH WAIT I GET WHAT YOUR SAYING NOW!!

I was being slow…

I get you now!

I was the one looking at it backwards!! I get it now…

Sorry for being slow lol

1 Like

…as usual…but gj …glad u noticed

1 Like

I get it now, i was the one being confused, i was looking at the value from a different perspective!

I thought i was checking from the Enemy, not the Player, i got the two mixed up and couldnt see it for the life of me.

The enemy is the one thats at 177º not the Player, the Player is at 0º, i was looking at it the other way around…

Im an idiot what can i say lol

1 Like

Harsh! …but fair I know when to admit when im being dumb haha

1 Like

i can’t be mad with same gd ver fellas

1 Like

Hahah no worries I can relate to this! Fresh eyes always help after working on something for a long time

1 Like