Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] How do I get the movement angle of a physics sprite?

Author
Message
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 21st Mar 2021 16:50

I think it must be something about taking GetSpritePhysicsVelocityX() and GetSpritePhysicsVelocityY() and then throwing them into some cosinustangus voodoo thing. But I can't rightly recall what, exactly.

The author of this post has marked a post as an answer.

Go to answer

chamaeleon
10
Years of Service
User Offline
Joined: 8th Mar 2014
Location:
Posted: 21st Mar 2021 17:21
This post has been marked by the post author as the answer.
Should be a matter of
basicFanatic
6
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 21st Mar 2021 17:54
Thanks, that's perfect! Just needed a bit of adjustment to make it fit the 3 o'clock clockwise standard:


Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 21st Mar 2021 18:21 Edited at: 21st Mar 2021 18:32
chamaeleon wrote: "ATan2(xvel, yvel)"

can someone confirm the parameter order for ATan2 where it states ATan2( y, x ) "exactly matches the C++ atan2 function"?

the y, then x order seems to be re-enforced within the parameter descripts, as well.

meanwhile:

ATan2(0,1) produces 0.0 (straight up)

&

ATan2(1,0) = 90.0 (3 o'clock)

...which is what we get from ATanFull with x,y parameter order?

since ATan2 doesn't offer example results (like AtanFull does), i'd like to know what we should expect from ATan2 (beyond the -180 to 180 range).

add: i just noted the example code for ATan2 includes: result#=ATan2(y#,x#) so, i'm still confused.
[My Itch.io Home] [Now Playing]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Mar 2021 23:17 Edited at: 21st Mar 2021 23:20
atan2(y,x) appears to be the order for c++
I think it has to do with where the origin is. Either stright up or pointing to the right. Also atan2() returns radians i think
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 22nd Mar 2021 00:55
@blink0k AppGameKit has a separate command for radians ATan2Rad, help states for certain that AppGameKit ATan2 is exactly the same as in C++ but in degrees

Win 7 Pro 64 bit SP1, AMD A4-5300 APU 3.4GHz, 8GB DDR3, NVidia GeForce GTX 750 1GB GDDR5, ASUS A55BM-E
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 22nd Mar 2021 01:02
Not sure why, but I'll take it. If I sub 90 from Atan2 results and wrap that angle, it works for all my stuff.

As I'm converting a Delphi game to AppGameKit right now, I noted that my Delphi code was more like 180-result, so the Atan2 implementation in AppGameKit is wrong/different.

Definitely degrees for aTan2 blink. Bit odd that it takes y,x though.
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 22nd Mar 2021 01:51 Edited at: 22nd Mar 2021 01:56
So I search terms was "atan2 in layman's terms and this is the main result(not a link but a paragraph on its own):
What does atan2 return?
atan2() method returns a numeric value between -π and π representing the angle theta of an (x, y) point. This is the counterclockwise angle, measured in radians, between the positive X axis, and the point (x, y)

Go further into an article linked below it and I came across;
Description
The Math.atan2() method returns a numeric value between -π and π representing the angle theta of an (x, y) point. This is the counterclockwise angle, measured in radians, between the positive X axis, and the point (x, y). Note that the arguments to this function pass the y-coordinate first and the x-coordinate second.



So there is confirmation of the order, in fact literally every result I read into said the same about the order. Couldn't really find out/work out why. Have no clue what is meant by between negative/positive pi so i am assuming that is something used under the hood so to speak.

Also worthy of note is that the angle in the pic is counter clockwise which I have also read a number of times in various articles. I keep reading that atan is useful for working out the arctangent of only 2 quadrants(1 and 4) whereas atan2 is useful for all 4(ie on the pic you can see the divisions making 4 quadrants). What the heck all this means is well, I do not know! I mean what the purpose of each is, is what is missing - ie how to choose which you would use, when you would use and why...so atanfull I found useful in DBP when working out how to rotate a tree to match its billboard based on the camera and then slowly rotate it once the billboard is no longer needed towards a fixed angle(search my thread history and choose Tree LOD as the code is there). I can only guess that atan and atan2 would be useful for performance reasons maybe?
Win 7 Pro 64 bit SP1, AMD A4-5300 APU 3.4GHz, 8GB DDR3, NVidia GeForce GTX 750 1GB GDDR5, ASUS A55BM-E
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 22nd Mar 2021 01:51 Edited at: 22nd Mar 2021 01:55
Edit double post cos the forum is being dumb, c'mon TGC I keep seeing this again and again - sometimes when you click "post" nothing happens, clicked it again nothing, refreshed page to make sure I had not lost my connection and boom...2 posts.
Win 7 Pro 64 bit SP1, AMD A4-5300 APU 3.4GHz, 8GB DDR3, NVidia GeForce GTX 750 1GB GDDR5, ASUS A55BM-E
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 22nd Mar 2021 02:11 Edited at: 22nd Mar 2021 02:13
thanks for the Atan info, James.

and, i've seen others with the double-post issue in the past day or so and have reported the matter.

add: just experienced it myself with this post. i'm on Edge. you?
[My Itch.io Home] [Now Playing]
[AGK Resource Directory] [TGC @ GitHub]
[CODE lang=agk] YOUR CODE HERE [/CODE]
[VIDEO=youtube] VIDEO ID [/VIDEO]
[AGK Showcase][Google Forum Search]
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 22nd Mar 2021 02:31
Chrome, I haven't had this issue myself until now it was almost as though that the server end is experiencing some form of lag from time to time, my experience was that the button highlighted on clicking both times, but nothing happened until an F5 refresh, or perhaps it is session issue as it did take some time for me to read up and type notes in this pages post/edit box which I then re organised into a semi understandable form before I actually clicked post reply
Win 7 Pro 64 bit SP1, AMD A4-5300 APU 3.4GHz, 8GB DDR3, NVidia GeForce GTX 750 1GB GDDR5, ASUS A55BM-E
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 22nd Mar 2021 02:33 Edited at: 22nd Mar 2021 02:38
As a test I just left the page open a while before posting prev msg...lets see if I quick post this msg and the issue persists, results in edit to follow...


Edit - well nope issue still exists! Edit option is responsive though

Edit 2 - subscription notification is not working either now, also when did email alerts stop? I haven't had a single one since returning to the forum!
Win 7 Pro 64 bit SP1, AMD A4-5300 APU 3.4GHz, 8GB DDR3, NVidia GeForce GTX 750 1GB GDDR5, ASUS A55BM-E

Login to post a reply

Server time is: 2024-04-27 00:23:21
Your offset time is: 2024-04-27 00:23:21