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 determine if an object is moving forward or backward

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th Dec 2018 22:26
I have the objects linear velocity and/or last position. How do i determine if it is moving forward or backward?
puzzler2018
User Banned
Posted: 18th Dec 2018 22:29 Edited at: 18th Dec 2018 22:34
positive or negative maybe

should always make

- velocity been backwards

velocity been forwards

0 = stopped

try not to make things difficult for yourselves to workout
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th Dec 2018 22:39 Edited at: 18th Dec 2018 22:40
Its a 3D obbject so it could be moving in ANY direction.
If i had a 3D equivalent command like GetSpriteXFromWorld() then i could do it. But i'm not sure how to do it with pure math
puzzler2018
User Banned
Posted: 18th Dec 2018 22:46
Unless you save any pre-coordinates before the movement happens.

oldx
oldy
oldz

move

newx
newy
newz

if oldx>newx then going forward unless backward
if oldy>newy then going forward unless backward
if oldz>newz then going forward unless backward

Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 18th Dec 2018 22:48
atanfull last position vs object rotation should give you what you need. If the last point is in rear half you are moving forward.
http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 18th Dec 2018 23:38
Ok Great! Thanks guys
Ortu
DBPro Master
16
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 19th Dec 2018 04:13 Edited at: 19th Dec 2018 04:27
sorry, was on mobile earlier, something like this. Not tested in agk, but i am assuming atanfull works the same in agk as it did in dbpro. If not Phaelax shared a universal implementation of the dbpro version years ago that I could dig up.

This is adapted from the process I use in Sulium to determine if something is in a character's frontal arc

http://games.joshkirklin.com/sulium

A single player RPG featuring a branching, player driven storyline of meaningful choices and multiple endings alongside challenging active combat and intelligent AI.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Dec 2018 05:15
Thanks Ortu,
I should have posted.
Another proggy dude told me to use DOT product of the two vectors and it worked.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 19th Dec 2018 05:22 Edited at: 19th Dec 2018 05:24
Ideally you just want the difference between two vectors
if your thinking of a car if you know the front of the cars
Vector and the back of the cars vector by subtracting
back from front should return positive or negative
depending on the direction I believe




oh scrub what I said lol DOT product that's the one can you tell my math is bad lol
fubar
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 19th Dec 2018 14:31
How do you apply the movement to the object? You said you have velocity but you'd need a direction vector too, and that vector should already tell you where the object is moving. If you have a vector (P) representing the direction the object is facing or pointing towards and vector (D) represent the direction of movement, you can take the dot product of the two and a result greater than 0 means it's moving forward. Less than 0 it's stepping backwards. And 0 would mean it's side-stepping left or right perpendicular to the direction it's facing.
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
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 19th Dec 2018 19:23
Yes. That's exactly what i did. Dot product. Voodoo magic. The devils math

Login to post a reply

Server time is: 2024-10-01 01:35:38
Your offset time is: 2024-10-01 01:35:38