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 / How to lerp properly from 350 degrees to 5 degrees?

Author
Message
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 1st Jul 2019 22:22
I've run into a problem using lerp.

Works fine unless I go from the high 300s to 5 degrees. You might see where this is going... The object will rotate counter clockwise once it makes the jump from 359 to 0 degrees. It then gets stuck in a loop.

Any guidance on how to handle this?
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st Jul 2019 22:32
have you got some example code ?
fubarpk
fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 1st Jul 2019 22:39
if you're comparing 2 wrapped angles to decide which way to rotate, try adding 360 to both, then compare.

otherwise, yeah, we need to know more about what you're trying to achieve.

Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 1st Jul 2019 22:51
Sorry, I solved it. I eneded up using the quaternion commands, instead of the angles.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Jul 2019 01:54
This has been asked a few times and I posted a solution in one of them a month or so ago
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 2nd Jul 2019 19:03
Well, the quats didn't work - the object would phase in and out occasionally. I couldn't find the thread you were referring to, Phaelex. I ended up doing this. Seems to work so far.

Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 3rd Jul 2019 01:04


It's a bit derpy code as I'm tired as heck right now., but for Degrees use 360.0 as the Range; and Radians use PHI (3.142...)
As I recall I had something not too dissimilar for a Gimble/Eular Lock hack in DBP., but of course it's better use to Matrix Rotation (Quaternions) to resolve such issues.
Don't know why AppGameKit doesn't have built-in Matrix Support like DBP, and it's Vector Support is a bit "Meh" but you can always manually create such with Arrays and Types.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Jul 2019 02:44
You could use tweens. That way you get timer based movement rather than frame based movement.
Couple of things to remember;
You need to use -180 through180 to represent your angles (or 0 through 360 if your going the other way)
You also need to add UpdateAllTweens(GetFrameTime()) before Sync()
Golelorn
8
Years of Service
User Offline
Joined: 20th Nov 2016
Location:
Posted: 3rd Jul 2019 03:32
Oh, wow. Nice, blink0k. I had no idea those existed! I will look into that.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 3rd Jul 2019 05:48
Make the second angle larger (Add 360 if smaller) than the first angle to rotate clockwise
Make the first angle larger (Add 360 if smaller) than the second angle to rotate counter clockwise

That seemed to work for me
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Jul 2019 00:46 Edited at: 4th Jul 2019 00:47
See if this fits what you want. (replace with whatever image)

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-22 21:10:00
Your offset time is: 2024-11-22 21:10:00