HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Angle Problems

07-07-2006, 08:25 PM#1
vile
I'm trying to rotate a unit around an X point.
The problem is that it's moving towards the point but its not rotating and I have no idea why.
This is inside a ForGroup function:

Collapse JASS:
function test takes nothing returns nothing
    local string s=GetAttachmentTable(GetExpiredTimer())
    local unit u=GetTableUnit(s, "u")
    local unit t=GetEnumUnit()
    local group e=GetTableGroup(s, "e")
    local real x1=GetTableReal(s, "x")
    local real y1=GetTableReal(s, "y")
    local real x2=GetUnitX(t)
    local real y2=GetUnitY(t)
    local real x
    local real y
    local string st=GetAttachmentTable(t)
    local real totaldist=GetTableReal(st, "dist")-2.5
    local real a=GetTableReal(st, "angle")+3.75
    if not IsUnitInGroup(t, e) then
        if totaldist>15 then
            set x=x2+2.5*Cos(a*bj_DEGTORAD)
            set y=y2+2.5*Sin(a*bj_DEGTORAD)
            call SetUnitPosition(t, x, y)
            call SetTableReal(st, "dist", totaldist)
        else
            call GroupAddUnit(e, t)
            call DisperseUnit(u, t)
        endif
    endif
    set u=null
    set t=null
    set hole=null
endfunction

I'm using bj_RADTODEG*Atan2(y2-y1, x2-x1)), as x1/y1 is the unit's coords and the x2/y2 is the point's coords, i keep increasing the angle by 3.75 per interval.

I tried setting the angle on each interval as well, and just increasing the angle each time, but still no luck.
07-07-2006, 09:09 PM#2
Alevice
IIRC, call SetUnitPosition(t, x, y) does not rotate the unit :/
07-07-2006, 09:23 PM#3
PipeDream
Collapse JASS:
            set x=x2+2.5*Cos(a*bj_DEGTORAD)
            set y=y2+2.5*Sin(a*bj_DEGTORAD)
As x2,y2 is the position of the unit, I believe you intended x1,y1.
07-07-2006, 09:24 PM#4
vile
using x2/y2 is moving the unit from its position + 2.5 distance towards the increased angle.. i still dont understand why it doesnt work.
07-07-2006, 09:30 PM#5
PipeDream
Please elaborate on your goal then. A picture would help.
07-07-2006, 09:44 PM#6
vile
imagine an X point

every unit that steps a distance from the X point, is added to a group
then they start swirling around the point in a circular motion, slowly on each interval they get closer to the point by 2.5 distance.
07-08-2006, 04:18 PM#7
PipeDream
Well Cos(a),Sin(a) is the radial unit vector. If you want the tangential unit vector perpendicular to it, -wSin(a),wCos(a). Which also happens to be the derivative with respect to time. w is the radians / second angular velocity you want.
07-08-2006, 07:27 PM#8
BertTheJasser
ATM I have no clue what you need, but maybe this is the solution (in case it works):[
Collapse JASS:
function test takes nothing returns nothing
    local string s=GetAttachmentTable(GetExpiredTimer())
    local unit u=GetTableUnit(s, "u")
    local unit t=GetEnumUnit()
    local group e=GetTableGroup(s, "e")
    local real x1=GetTableReal(s,"x")
    local real y1=GetTableReal(s,"y")
    local real x2=GetUnitX(t)-x1
    local real y2=GetUnitY(t)-y1
    local real d=SquareRoot(y2*y2+x2*x2)-2.5 
    local real a=Atan2(y2,x2)+3.75*bj_DEGTORAD
    if not IsUnitInGroup(t, e) then
        if totaldist>15 then
            call SetUnitPosition(t,x1+d*Cos(a),y1+d*Sin(a))
        else
            call GroupAddUnit(e,t)
            call DisperseUnit(u,t)
        endif
    endif
    set u=null
    set t=null
    set hole=null
endfunction
EDIT: -Removed unnecisseray(?) Pows
EDIT: -Removed a useless line of code
07-08-2006, 08:21 PM#9
vile
I'll try that out. btw, using Powers is a bad habit when it's not needed.
07-08-2006, 08:47 PM#10
Blade.dk
Same with SquareRoot.
07-09-2006, 07:25 AM#11
vile
SquareRoot is essencial in this script, you cant calculate the distance without it.
07-09-2006, 09:57 AM#12
BertTheJasser
This would require a test,... what do i say .. there was a test between Pow(x,2) in the same func and x*x in an extra func and some other stuff. I think the diffrence was not hat big. But you are right, replacing with x*x is essentially(?) better.
07-09-2006, 11:36 AM#13
iNfraNe
The difference was very significant actually... Its always better to use x*x over Pow(x,2)
07-09-2006, 12:19 PM#14
Pheonix-IV
Why not just use polar co-ordinates?
07-09-2006, 12:42 PM#15
iNfraNe
He does use polar coordinates.