|
Post by NASH7777 on May 16, 2005 7:20:24 GMT -5
Well I need to make a tangent system. Basically I use the event Face leader command to get events to shoot stuff at the leader. But let's say I want the leader to turn a certain degree somewhere for an attack or an event to face another event. I'm hoping some tig will help me here,, and maybe someone will help me ;-)
So I will have two sets of XY variables. One for event one for event 2 x1, x2, y1, y1
I think all I need to do is find their difference then depending if I get ++, +-, , -+or -- for the differences I will have it face a different Cardinal direction then after that direction I will need to move it clockwise (c-clockwise) a certain degree to make it right on.
So I take the tangent of the fraction opp/adj. But I need a way to find the tangent first. I'll work on it in school today....
__________ |................./ <this corner angle, where character one is at |.............../ |............./ |.........../ |........./ |......./ |...../ |.../ |./ / < here's character 2
|
|
|
Post by Rodak on May 16, 2005 7:50:04 GMT -5
So I take the tangent of the fraction opp/adj. But I need a way to find the tangent first. I have not cracked a Trigonometry book in years, but if I recall correctly Tangent=Opposite/Adjacent, so you are trying to take the tangent of the tangent in this case. Opp/Adj should be enough right there. ========== OK, I read your post in more detail on my break here at work and I think this is going to be more involved than I first anticipated. I keep wanting roots or exponents for the distance formula or the Pythagorean theorum. I'll check my reference after work if you have not solved it at school. This should be fun for a math teacher!
|
|
|
Post by NASH7777 on May 16, 2005 11:31:19 GMT -5
No I didn't mean a tangent of a tangent lol, just the plain tangent lol.
Okay I have a method that'll work and the most I can get off is 2.1 degrees, well 2 I guess. Basically I manually turn the party to 1 of the 8 directions that matches so its right on or I'm slightly off but can adjust clockwise.
Then to figure out how much to rotate clockwise I do this.
A/B = C/360 (A and B being Opp/Adj and given)
SO I divide 360 by B first then multiply that by A to get what C would be. Then I take C and multiply it by 0.159154. (to achieve this with RPGM2 I will just add zeros to the end then get rid of them later).
The get it to the closest degree and Rotate it clockwise from that point those degrees. I will just use a repeat command, minusing 1 from it each time and adding one to the event's angle until it reaches 0.
This should work okay, and at most being off 2 measely degrees it's pretty dang good.
|
|
|
Post by Rodak on May 16, 2005 13:00:40 GMT -5
OK, I can follow most of that. But if you want it to be of help to anyone else it may be a good idea to post it in either script or tutorial form.
A script version of how to calculate distance from the party and/or party's angle would be a Great addition to your common script database. You might see more games you like from other people!
Glad you got it going.
Now I can let my Trigonometry reference continue to gather dust.
Peace.
|
|
|
Post by NASH7777 on May 16, 2005 15:50:05 GMT -5
Yeah I'll have to draft out the exact scripting, test it, then I'll post it in the common script database.
|
|
Thrull
RPG Maker-in-Training
Posts: 16
|
Post by Thrull on May 16, 2005 23:36:55 GMT -5
Rodak is correct. This easy.
To get the angle use Opposite/Adjacent. To get the distance use pythagorian's triangles. A^2 + B^2 = C^2. You'll know A and B, so you can calculate C with ease.
|
|
|
Post by Rodak on May 17, 2005 3:47:34 GMT -5
A^2 + B^2 = C^2. You'll know A and B, so you can calculate C with ease. I hate to tell you, but RPGM2 is Mathematically Challenged. No roots or exponents. While exponents can be scripted around (A x A = A^2), roots are different. Without exponents you cant even do C^1/2 for a square root. I look forward to seeing how this is done "Brute Force" style. I know it can be done, but I forget how.
|
|
|
Post by NASH7777 on May 17, 2005 7:10:33 GMT -5
It's pretty simple to make a system that calculates an aproximate square root. There's already 3 or 4 methods people have done this. Actually for my distance script I didn't use the Pathagorean theorum, basically it wasn't really needed. I just compare distanceX and dY. This gives me attack ranges that are more square like then circular but to be honest I need it this way. And most often my attacks hit a 3x3 grid not a diamond one for explosions and such. Now for really big explosions a circular one may be better but anything that big I haven't really gotten to.
|
|
Thrull
RPG Maker-in-Training
Posts: 16
|
Post by Thrull on May 17, 2005 21:04:00 GMT -5
Ugh. It can't even take roots? I can't think of any game that doesn't use square roots on occasion.
Its still possible to do if you don't mind a best guess. Since there are only so many triangle you can make (see below), you should just be able to write all the data to memory and not have to worry about calculating it.
I don't know how big the area is but let's assume its 3 by 3 for the example. You'd have to find the angles for triagles with sides of:
1,1 1,2 1,3 2,2 2,3 3,3
This isn't so bad for a 3 by 3 grid, but it may get annoying with bigger grids. Still it should be doable by doing it this way instead of the easy way.
Rant... The Ancient Greeks new about Roots! Why do so few people (and game companies use things we've know about for 2000+ years?! It isn't terribly difficult to program either.
Edit: WAIT! Its possible to make a for loop that can guess the square root of X. It isn't terribly hard to do either! The more for loops, the more accurtae it gets, but you shouldn't need anything beyond 2 deimal places. I'll have to rewrite it tonight sometime. HA! Take that math-haters.
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 17, 2005 22:55:32 GMT -5
There's a way to find square roots...
Make a script like so
TempFlagx = Off TempFlagy = Off Tempvariablex = 0 Script Branch: Repeat: TempFlagx = Off Tempvariablex = Tempvariablex + 1 Tempvariablex2 = Tempvariablex * Tempvariablex Script: Condition: Tempvariable2 = Tempvariabley TempFlagx = On Condition: End Script: Condition: Tempvariablex2 =/ Tempvariabley (=/ represents 'is not equal to') Tempvariablex2 = Tempvariablex2 - Tempvariabley Script: Condition: Tempvariablex2 >= 1 TempFlagx = On TempFlagy = On Condition: End Script: Condition: Tempvariablex2 <= -1 Branch: To Top Condition: End Conditon: End Branch: End Script: Condition: TempFlagy = On Tempvariablex = Tempvariablex -1 Condition: End
Then whenever you want to find a square root do this
Tempvariabley = (number you want to find square root of) Script: Call (script above) (Tempvariablex will return as the square root of Tempvariabley) (If no exact square root was found, Tempvariablex will return as the whole number below it's square root, for example, if the square root would've been 2.348657 etc. it would come back as 2) (If you enter Tempvariabley as 0 it may not work correctly, so you can script around that at the beginning) (If you enter a negative value for Tempvariabley it will not work)
This should work perfectly. I may have made a mistake but I don't think so. This is also how you'd script the same thing in Java.
|
|
|
Post by vespuleth on May 18, 2005 1:33:40 GMT -5
*shakes head* me and doan had this discussion a LONG time ago. the most efficient way to do square roots is:
1) sqrtdev=2 2) repeat while sqrtdev /= sqrt 3) sqrt = sqrtdev 4) sqrt = tempvar0/sqrt 5) sqrtdev = sqrt + sqrtdev 6) sqrtdev = sqrtdev/2 7) end repeat
before you do this, be sure to plug the number you want the square root of into tempvar0 (look for its reference in the formula). also, name one variable sqrtdev (for square root deviation) and one variable sqrt (for square root).
doan posted a method as well (i am pretty sure thats the one that william posted). it employed two scripts. the major differences between his and mine were that mine was alot smaller, but his would, if you have a non perfect root (ie x.12345) it would round to the nearest number (if it was >x.4999999 it would round up). if anyone wants to see doans method, let me know, and i will post it.
and for the record, this script works in java as well.
|
|
|
Post by vespuleth on May 18, 2005 1:35:57 GMT -5
doans method (a new post for organizations sake):
Script: Square Root var4 = sqrt / 1,000,000 var3 = sqrt / 10,000 var3 = var3 % 100 var2 = sqrt / 100 var2 = var2 % 100 var1 = sqrt % 100 flag0 = Off sqrt = 0 var5 = 0 var8 = 1000 var0 = var4 Call [SquareRootCalc] var0 = var3 + var0 Call [SquareRootCalc] var0 = var2 + var0 Call [SquareRootCalc] var0 = var1 + var0 Call [SquareRootCalc] flag0 = On Call [SquareRootCalc]
Script: SquareRootCalc var6 = 0 Repeat (flagOff=Off) var6 = var6 + 1 var7 = var5 + var6 var7 = var6 x var7 Condition (var0 = var7) SB: To End Condition End Condition (var0 < var7) var6 = var6 - 1 SB: To End Condition End Branch End Condition (flag0 = On) Condition (var6 >= 5) sqrt = sqrt + 1 Condition End Force Script End Condition End var7 = var5 + var6 var7 = var6 x var7 var0 = var0 - var7 var0 = var0 x 100 var7 = var6 x var8 sqrt = sqrt + var7 var5 = var5 x 100 var7 = var6 x 20 var5 = var5 + var7 var8 = var8 / 10
like i said, doans script is a little more accurate (it will round up an x.5 where mine wont.
|
|
|
Post by vespuleth on May 18, 2005 1:41:18 GMT -5
|
|
|
Post by Rodak on May 18, 2005 3:48:37 GMT -5
And THAT, folks, is why I called it "Brute Force" and also very probably why I could not recall the technique (but still knew the proper definition of Tangent). Don't forget; Pytahgorus made a religion out of Math. He went so far as to actually MURDER the man who showed him the proof that the square root of 2 is an irrational number. Numbers were supposed to be perfect. While some historians argue the Murder charge, it is known that shortly after Pythagorus was presented with this concept he took the Geometer who made the proof out on a fishing trip on which the poor soul had a fatal accident. Yeah right... it was Murder!! And EUREKA! is Greek for "This Bath is Too Hot!" Oh yeah; Ugh. It can't even take roots? Yes, I have often thought it ironic that a pocket calculator has more Math Power that RPGM2. And; There are people who hate Math? BLASPHEMY!! Fetch Pythagorus! Peace. =+=+=+=+=+=+= EDIT: =+=+=+=+=+=+= I just read the post over at Agetec and Doan left out something Vitally Important... When he asks what is the Square Root of 69 (the answer to which is, obviously, 8 something), he failed to follow it up with What is the Square Root of -69?... i 8 something, of course!
|
|
Thrull
RPG Maker-in-Training
Posts: 16
|
Post by Thrull on May 19, 2005 3:10:16 GMT -5
Well, once again better scripters have beaten me to the punch. I has assumed that you'd ever only need 3 decimal places, so I wrote 3 quick for loops that run through numbers. Ah well.
|
|