• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] JASS Polar Offset with X/Y

Status
Not open for further replies.
Level 20
Joined
Jul 14, 2011
Messages
3,213
Hi! I'm trying to create some "Charge Field" where units are created and moves towards the caster, but I'm having problems to set the "Polar Offset towards the Caster" I wonder if this would work...

JASS:
    local unit Caster = GetEnumUnit()
    local real CasterX = GetUnitX(Caster)
    local real CasterY = GetUnitY(Caster)
    local unit BeamCharge
    local real x = CasterX + 500 * Cos(GetRandomReal(0, 360) * bj_DEGTORAD)
    local real y = CasterY + 500 * Cos(GetRandomReal(0, 360) * bj_DEGTORAD)
    local group g = CreateGroup()
    local real Radians
     
    if GetUnitCurrentOrder(u) == OrderId("channeling") then
   
    set BeamCharge = CreateUnit(p, 'h000', x, y, bj_UNIT_FACING)
    call UnitApplyTimedLife(BeamCharge, 'BTLF', 1)

    call GroupEnumUnitsInRange(g, CasterX, CasterY, 500, null)
    loop
        set BeamCharge = FirstOfGroup(g)
        exitwhen BeamCharge == null
        if (GetUnitTypeId(BeamCharge) == 'h000') then
            set Radians = Atan2(CasterY-GetUnitY(BeamCharge), CasterX-GetUnitX(BeamCharge))
            call SetUnitX(BeamCharge, CasterX+Cos(Radians)*25)
            call SetUnitY(BeamCharge, CasterY+Cos(Radians)*25)
        endif
        call GroupRemoveUnit(g,BeamCharge)
    endloop

    call DestroyGroup(g)
    set Caster = null
    set BeamCharge = null
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Thanks for that :p I didn't notice the "Sin" thing. But the units still doesn't move. They're created but not moved =/
 
Last edited:
Well, one possible thing could be that the group is empty. Try adding a debug message within the loop (inside the if-statement) and see if it is displayed. If it is, then that means the group has some beam charges. If it isn't, then something is wrong on that front.

Otherwise, the SetUnitX/Y() might be the issue. If I understand correctly, the beam unit should be moving towards the caster, starting from a 500 distance. The problem lies in these lines:
JASS:
call SetUnitX(BeamCharge, CasterX+Cos(Radians)*25)
call SetUnitY(BeamCharge, CasterY+Cos(Radians)*25)
I think you should put the x and y of the beam charge rather than the caster's, because then it will just be in the same position from the start.

Hopefully it works, good luck.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I was using "Set Unit X" and "Set Unit Y"... and wasn't working. I just changed "SetUnitPosition(Unit, x, y) and worked :p
 
Level 16
Joined
Mar 3, 2006
Messages
1,564
Try making this
JASS:
 local real x = CasterX + 500 * Cos(GetRandomReal(0, 360) * bj_DEGTORAD)
 local real y = CasterY + 500 * Sin(GetRandomReal(0, 360) * bj_DEGTORAD)

to

JASS:
 local real x = CasterX + 500 * Cos(GetRandomReal(0, 2*bj_PI))
 local real y = CasterY + 500 * Sin(GetRandomReal(0, 2*bj_PI))

That way you don't even need the constant bj_DEGTORAD

(Mag is the one who told me this)
 
Status
Not open for further replies.
Top