| 02-12-2009, 01:51 AM | #1 |
I'm just starting to dwell more into JASS and i've been messing around with some scripts from wc3jass but i cant seem to figure them out. I am trying to make a unit circle another unit at an appropriate speed/distance. I tried using UnitCircleUnit script, but i can't figure out Handles yet, so i dont know. I am just wondering another way to do this. |
| 02-12-2009, 03:27 AM | #2 |
Handles are any thing which extends a handle... Things that extend handle: everything EXCEPT reals, integers, and strings. Just pass two units as the handle values; otherwise I'm not entirely sure what this script is. to do this yourself; keep reading: P1 is always r units away from Po. To do this; simply set the value of P1x = Pox + r*cos(angle) and P1y = Poy + r*sin(angle) In this In this case: P1 = Rotating unit's x/y Po = Caster unit. r = Radius of the circle. To get the angle between two points; you know the formula is: Atan2(yo-y1, xo-x1) That's really all you need to do. The math behind it is really quite simple trig; if you know the ratio formed by your line you can multiply it by the radius to get the curvature. And you know cos is the relation of angular X to r based on angle and sin is the relation of angular Y to r based on angle. The reason this creates a circle is because after 2Pi rotations you've completed a full circle across both sin and cos. (Actually in this case; the value is -Pi to Pi because of the nature of Atan) Hope that explains it? - If not I posted code that will do it; hopefully it brings things together. [edit] Looking over this I explained it poorly so here's some code: JASS:function GetAngle takes real x1, y1, x2, y2 returns real return Atan2(y2-y1, x2-x1) //Returns a value from -Pi to Pi endfunction function PolarProjection takes unit caster, unit rotating, real dist returns nothing local real xorig = GetUnitX(caster) //Self explanditory. local real yorig = GetUnitY(caster) local real x = GetUnitX(rotating) local real y = GetUnitY(rotating) local real angle = GetAngle(xorig,yorig,x,y) //It doesn't reall matter which way you pass these as long as x/y are correct. //The difference will usually be a positive VS negative answer, both are good //it depends on the direction you want your motion to be in. call SetUnitX(rotating, xorig + r*Cos(angle)) //Xorigin + radius * xcontribution% call SetUnitY(rotating, yorig + r*Sin(angle)) //Yorigin + radius * ycontribution% endfunction |
| 02-13-2009, 12:29 AM | #3 |
thanks Blackroot |
