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º 0º… 180º
…-90º
…positive degrees go above the Object and negative degrees go bellow the Object.
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.
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.
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.
Thanks for all the effort, your explanation made perfect sense
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:
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.