Why isn't unit moving?

Lightstalker

New Member
Reaction score
55
For some reason, the BASICATK unit is not moving. However, the BJDebugMsg displays its name correctly.

Code:

JASS:
scope AttackMovement initializer Init

    globals
        group TEMPGROUP = CreateGroup()
        group TEMPGROUP2 = CreateGroup()
    endglobals

    private function UnitIsDummy takes nothing returns boolean
        return GetUnitTypeId(GetFilterUnit()) == BASICATK
    endfunction
    
    private function UnitIsEnemy takes nothing returns boolean
        return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetFilterUnit())) == true
    endfunction
    
    private function Callback takes nothing returns nothing
        local unit u = GetEnumUnit()
        local unit enemy = null
        local real angle = GetUnitFacing(u)
        local real x = GetUnitX(u) + 20.0 * Cos(angle * bj_DEGTORAD)
        local real y = GetUnitY(u) + 20.0 * Sin(angle * bj_DEGTORAD)
        call BJDebugMsg(GetUnitName(u))
        call SetUnitPosition(u, x, y)
        call GroupEnumUnitsInRange(TEMPGROUP2, GetUnitX(u), GetUnitY(u), 150.0, Condition(function UnitIsEnemy))
        loop
        set enemy = FirstOfGroup(TEMPGROUP2)
        exitwhen enemy == null
            call UnitDamageTarget(u, enemy, 250.0, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS)
            call RemoveUnit(u)
        call GroupRemoveUnit(TEMPGROUP2, enemy)
        endloop
        
        set u = null
    endfunction
        

    private function Actions takes nothing returns nothing        
        call GroupEnumUnitsInRect(TEMPGROUP, MAPENTIRE, Condition(function UnitIsDummy))
        call ForGroup(TEMPGROUP, function Callback)
    endfunction

    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterTimerEvent(t, 0.15625, true)
        call TriggerAddAction(t, function Actions)
    endfunction
endscope
 

Lightstalker

New Member
Reaction score
55
Hmm a mistake... Still, shouldn't affect its movement.

EDIT: After testing, it had no effect on movement (and shouldn't have either).
 

ZugZugZealot

New Member
Reaction score
33
He's using sine and cosine properly, think of the basics...

cos(Δ) = a/h
h * cos(Δ) = a

sin(Δ) = o/h
h * sin(Δ) = o

Think of Δ being the unit facing, and think of h as the distance to be moved. a is a projected X to change the current X. o is a projected Y to change the current Y.

I don't currently have any ideas as to why it doesn't work, however, have you tried putting a display message after the SetUnitPosition() function? Also... Have you tried doing text displays on X and Y { [ljass]call BJDebugMsg( "X = " + R2S(x) + "\nY = " + R2S(y))[/ljass] } with the unit starting at [0,0] to see if they're even natural?
 

Lightstalker

New Member
Reaction score
55
Also... Have you tried doing text displays on X and Y { [ljass]call BJDebugMsg( "X = " + R2S(x) + "\nY = " + R2S(y))[/ljass] } with the unit starting at [0,0] to see if they're even natural?

Just tried this. It worked fine, (x & y displayed). However, the numbers for X seemed to remain constant. Y seemed to increase/decrease a bit (by 20 or so).

Strangely enough, I made a GUI trigger to test this, and it would not work with the GUI trigger, just the vJASS one.
 

chobibo

Level 1 Crypt Lord
Reaction score
48
cos(90)=0, anything multiplied by 0 is 0, hence if x=10 then the equation x=x+20*Cos(90) would yield a constant value, which is 10.

Try using SetUnitX and SetUnitY just to see if those would make the unit move.
 

ZugZugZealot

New Member
Reaction score
33
The fact that the unit is facing 90 and isn't moving X only proves he's using his math correctly. Also, even though there's a 0 x change, there's still a y change, which means the unit should STILL move. Though if he wants to test both X and Y movement, he could use 36.8699 unit facing angle to test both X and Y, which should project an X of about 16, and a Y of about 12.

Going outside the box (code), what is your dummy unit's base, what kind of abilities does it have, etc?

Oh YEAH! I thought of another thing, how many times is it suppose to move? Because a distance of 20 over 0.15625 is REALLY REALLY REALLY REALLY REALLY REALLY slow movment, since 20 units is hardly anything at all, depending on how many times it's suppose to move, if it were to let's say move only once, it would look like it hasn't moved at all. So yeah do something like use GetUnitX and GetUnitY, but not to make it move, that wouldn't work, but to see its new position...
[ljass]call SetUnitPosition(u, x, y)[/ljass]
[ljass]call BJDebugMsg( "X = " + R2S(GetUnitX(u)) + "\nY = " + R2S(GetUnitY(u)) )[/ljass]
 

chobibo

Level 1 Crypt Lord
Reaction score
48
Oh a typo lol!, I meant try using the SetUnitX and SetUnitY natives, or maybe your dummy unit has 0 movement speed...
 

Lightstalker

New Member
Reaction score
55
The dummy is based off of Albatross. The only ability it has is Locust. It works fine if I make the trigger in GUI.

The unit is supposed to move 20 every 0.1 seconds, and not 20 OVER 0.1 seconds.

This is a rough equivalent in GUI:

Trigger:
  • Atk Mov GUI
    • Events
      • Time - Every 0.02 seconds of game time
    • Conditions
    • Actions
      • Set G1 = (Units of type Basic Attack)
      • Unit Group - Pick every unit in G1 and do (Actions)
        • Loop - Actions
          • Set P1 = (Position of (Picked unit))
          • Set P2 = (P1 offset by 25.00 towards (Facing of (Picked unit)) degrees)
          • Unit - Move (Picked unit) instantly to P2
          • Set G2 = (Units within 150.00 of P2 matching (((Matching unit) belongs to an enemy of (Owner of (Picked unit))) Equal to True))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Number of units in G2) Greater than 0
            • Then - Actions
              • Unit - Remove (Picked unit) from the game
              • Unit - Cause (Picked unit) to damage (Random unit from G2), dealing 100.00 damage of attack type Chaos and damage type Universal
            • Else - Actions
          • Custom script: call RemoveLocation(udg_P1)
          • Custom script: call RemoveLocation(udg_P2)
          • Custom script: call DestroyGroup(udg_G2)
      • Custom script: call DestroyGroup(udg_G1)


It works perfectly.
When converted to JASS, it yields the following:

JASS:
function Trig_Atk_Mov_GUI_Func002Func004002003 takes nothing returns boolean
    return ( IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetEnumUnit())) == true )
endfunction

function Trig_Atk_Mov_GUI_Func002Func005C takes nothing returns boolean
    if ( not ( CountUnitsInGroup(udg_G2) > 0 ) ) then
        return false
    endif
    return true
endfunction

function Trig_Atk_Mov_GUI_Func002A takes nothing returns nothing
    set udg_P1 = GetUnitLoc(GetEnumUnit())
    set udg_P2 = PolarProjectionBJ(udg_P1, 25.00, GetUnitFacing(GetEnumUnit()))
    call SetUnitPositionLoc( GetEnumUnit(), udg_P2 )
    set udg_G2 = GetUnitsInRangeOfLocMatching(150.00, udg_P2, Condition(function Trig_Atk_Mov_GUI_Func002Func004002003))
    if ( Trig_Atk_Mov_GUI_Func002Func005C() ) then
        call RemoveUnit( GetEnumUnit() )
        call UnitDamageTargetBJ( GetEnumUnit(), GroupPickRandomUnit(udg_G2), 100.00, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL )
    else
    endif
    call RemoveLocation(udg_P1)
    call RemoveLocation(udg_P2)
    call DestroyGroup(udg_G2)
endfunction

function Trig_Atk_Mov_GUI_Actions takes nothing returns nothing
    set udg_G1 = GetUnitsOfTypeIdAll('n000')
    call ForGroupBJ( udg_G1, function Trig_Atk_Mov_GUI_Func002A )
    call DestroyGroup(udg_G1)
endfunction

//===========================================================================
function InitTrig_Atk_Mov_GUI takes nothing returns nothing
    set gg_trg_Atk_Mov_GUI = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Atk_Mov_GUI, 0.02 )
    call TriggerAddAction( gg_trg_Atk_Mov_GUI, function Trig_Atk_Mov_GUI_Actions )
endfunction


Note that the PolarProjectionBJ (point with offset) is actually doing this:

JASS:
function PolarProjectionBJ takes location source, real dist, real angle returns location
    local real x = GetLocationX(source) + dist * Cos(angle * bj_DEGTORAD)
    local real y = GetLocationY(source) + dist * Sin(angle * bj_DEGTORAD)
    return Location(x, y)
endfunction


To better test x & y, I remade the attack trigger in GUI and made it to fire only a single projectile at once:

Trigger:
  • Untitled Trigger 002
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Unit - Create 1 Basic Attack for Player 1 (Red) at (Position of (Random unit from (Units owned by Player 1 (Red) of type Officer))) facing (Facing of (Random unit from (Units owned by Player 1 (Red) of type Officer))) degrees


Strangely enough, my AttackMovement trigger will not fire in combination with the GUI trigger (I have tested this using BJDebugMsg). However, when testing it in combination with the vJASS attack trigger, it will work fine, but the unit will still not move.
 

ZugZugZealot

New Member
Reaction score
33
JASS:
scope MoveIt initializer Init
    globals
        private trigger trig
    endglobals
    
    private function Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local real x = GetUnitX(u) + (100 * Cos(GetUnitFacing(u) * bj_DEGTORAD ))
        local real y = GetUnitY(u) + (100 * Sin(GetUnitFacing(u) * bj_DEGTORAD ))
        
        call SetUnitPosition( u, x, y )
        
        set u = null
    endfunction

    private function Init takes nothing returns nothing
        local integer i
        
        set trig = CreateTrigger()
        
        set i = 0
        loop
            exitwhen i > 11
            call TriggerRegisterPlayerUnitEvent( trig, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
            set i = i + 1
        endloop
        call TriggerAddAction( trig, function Actions )
    endfunction
endscope
Though it's not directly related to your case, but I slapped this together and it works.
 

Sevion

The DIY Ninja
Reaction score
413
JASS:
scope AttackMovement initializer Init
    globals
        group TEMPGROUP = CreateGroup()
        group TEMPGROUP2 = CreateGroup()
    endglobals

    private function UnitIsDummy takes nothing returns boolean
        return GetUnitTypeId(GetFilterUnit()) == 'hpea'
    endfunction
    
    private function UnitIsEnemy takes nothing returns boolean
        return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetFilterUnit())) == true
    endfunction
    
    private function Callback takes nothing returns nothing
        local unit u = GetEnumUnit()
        local unit enemy = null
        local real angle = GetUnitFacing(u)
        local real x = GetUnitX(u) + 20.0 * Cos(angle * bj_DEGTORAD)
        local real y = GetUnitY(u) + 20.0 * Sin(angle * bj_DEGTORAD)
        call SetUnitPosition(u, x, y)
        call GroupEnumUnitsInRange(TEMPGROUP2, GetUnitX(u), GetUnitY(u), 150.0, Condition(function UnitIsEnemy))
        loop
            set enemy = FirstOfGroup(TEMPGROUP2)
            exitwhen enemy == null
            call UnitDamageTarget(u, enemy, 250.0, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS)
            call RemoveUnit(u)
            call GroupRemoveUnit(TEMPGROUP2, enemy)
        endloop
        
        set u = null
    endfunction
        

    private function Actions takes nothing returns nothing        
        call GroupEnumUnitsInRect(TEMPGROUP, MAPENTIRE, Condition(function UnitIsDummy))
        call ForGroup(TEMPGROUP, function Callback)
        call GroupClear(TEMPGROUP)
    endfunction

    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), 0.15625, true, function Actions)
    endfunction
endscope


Works fine for me. Though, you might want to rethink the period. 0.15625 is a weird-ass random number.... Plus, it's VERY choppy :p
 

Lightstalker

New Member
Reaction score
55
JASS:
scope AttackMovement initializer Init
    globals
        group TEMPGROUP = CreateGroup()
        group TEMPGROUP2 = CreateGroup()
    endglobals

    private function UnitIsDummy takes nothing returns boolean
        return GetUnitTypeId(GetFilterUnit()) == 'hpea'
    endfunction
    
    private function UnitIsEnemy takes nothing returns boolean
        return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetFilterUnit())) == true
    endfunction
    
    private function Callback takes nothing returns nothing
        local unit u = GetEnumUnit()
        local unit enemy = null
        local real angle = GetUnitFacing(u)
        local real x = GetUnitX(u) + 20.0 * Cos(angle * bj_DEGTORAD)
        local real y = GetUnitY(u) + 20.0 * Sin(angle * bj_DEGTORAD)
        call SetUnitPosition(u, x, y)
        call GroupEnumUnitsInRange(TEMPGROUP2, GetUnitX(u), GetUnitY(u), 150.0, Condition(function UnitIsEnemy))
        loop
            set enemy = FirstOfGroup(TEMPGROUP2)
            exitwhen enemy == null
            call UnitDamageTarget(u, enemy, 250.0, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_UNIVERSAL, WEAPON_TYPE_WHOKNOWS)
            call RemoveUnit(u)
            call GroupRemoveUnit(TEMPGROUP2, enemy)
        endloop
        
        set u = null
    endfunction
        

    private function Actions takes nothing returns nothing        
        call GroupEnumUnitsInRect(TEMPGROUP, MAPENTIRE, Condition(function UnitIsDummy))
        call ForGroup(TEMPGROUP, function Callback)
        call GroupClear(TEMPGROUP)
    endfunction

    private function Init takes nothing returns nothing
        call TimerStart(CreateTimer(), 0.15625, true, function Actions)
    endfunction
endscope


Works fine for me. Though, you might want to rethink the period. 0.15625 is a weird-ass random number.... Plus, it's VERY choppy :p

It was supposed to be 0.015625 :p
But your trigger does not work for me :( (Yes, I made sure to change the unit type of the unit)
 

GoGo-Boy

You can change this now in User CP
Reaction score
40
Is the movement speed of your dummy unit greater than 0?
Else it doesn't work.

Edit: Also that might explain why they units x and y values aren't differing at all when you debug them. However if you say that the "y" movement does increase and decrease a bit each time I'm not sure :s
 
General chit-chat
Help Users
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top