Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   More of a math question... (https://forums.graalonline.com/forums/showthread.php?t=73767)

DustyPorViva 04-30-2007 10:29 PM

More of a math question...
 
1 Attachment(s)
Okay, say I have a number of directions, in this example, 16.
I have a set dir1, 6.
And I also have dir2, 1.

How would I get the 'distance', or in this case, the number of directions dir1 is from dir2?
I know in the example I posted with it, it's 2 directions away, but what would be the formula to do this? The problem arises since, like in the example, dir1 is 15, and dir2 is 1, so abs(dir2-dir1)=14.
If any of this makes sense, any advice?

zokemon 04-30-2007 10:46 PM

Quote:

Originally Posted by DustyPorViva (Post 1304651)
Okay, say I have a number of directions, in this example, 16.
I have a set dir1, 6.
And I also have dir2, 1.

How would I get the 'distance', or in this case, the number of directions dir1 is from dir2?
I know in the example I posted with it, it's 2 directions away, but what would be the formula to do this? The problem arises since, like in the example, dir1 is 15, and dir2 is 1, so abs(dir2-dir1)=14.
If any of this makes sense, any advice?

I would suggest just doing something like:

dist = abs(dir2 - dir1);
if (dist > 8) dist = 16 - dist;

DustyPorViva 04-30-2007 11:19 PM

Thanks, that worked great. :)
Though I ended up doing:
dist=abs(dir2-dir1)>8?16-abs(dir2-dir1):abs(dir2-dir1);

zokemon 04-30-2007 11:22 PM

Quote:

Originally Posted by DustyPorViva (Post 1304663)
Thanks, that worked great. :)
Though I ended up doing:
dist=abs(dir2-dir1)>8?16-abs(dir2-dir1):abs(dir2-dir1);

Hehe.
I just have an OCD think about repeating the same math formula over and over again :P

DustyPorViva 05-01-2007 12:03 AM

Oh I know, I thought the same thing at first... but meh, dunno, keeps it to one line so I like it.

Gambet 05-01-2007 12:05 AM

Quote:

Originally Posted by zokemon (Post 1304666)
Hehe.
I just have an OCD think about repeating the same math formula over and over again :P



Then do something like....


PHP Code:

temp.var = abs(dir2 dir1);
dist = (temp.var > 16 temp.var : temp.var); 



All times are GMT +2. The time now is 03:32 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.