Movement Speed Calculation

Ayanami

칼리
Reaction score
288
Basically, I'm trying to reduce movement speed of a unit by a flat amount. Let's say I want to reduce a unit's movement speed by 50, initially it was like this (using T32):
JASS:

private static method periodic takes nothing returns nothing
    // other code
    
    // movement speed part, this.u relates to the unit
    call SetUnitMoveSpeed(this.u, GetUnitDefaultMoveSpeed(this.u))
    call SetUnitMoveSpeed(this.u, GetUnitMoveSpeed(this.u) - 50)
endmethod


Let's take a scenario. A unit with 300 MS. Let's say unit has Boots, which boosts 50 MS permanently. Above formula would work fine as it sets the unit's speed to default (300), but then would also take account of permanent MS bonus like Boots, thus the unit's speed is actually set to 350. Unit's current speed is then retrieved (350) then is reduced by 50. Thus, unit would have a total of 300 MS after the 50 MS reduction, which works fine. But when % MS factor comes in, the above doesn't work anymore.

Again, unit has 300 MS. Unit now has aura that boosts 10% MS. Unit has a total of 330 MS. Unit's MS is set to default, which becomes 330 after aura effect. Unit's speed is then reduced to 280 (330 - 50). However, due to the aura, Unit's speed is set to 308 (280 * 1.1). Thus, I came up with a new code:
JASS:

private static method periodic takes nothing returns nothing
    // other code
    
    // movement speed part, this.u relates to the unit (comment shows the value of the variables for clarity sake)
    local real old
    local real new
    local real r
    call SetUnitMoveSpeed(this.u, GetUnitDefaultMoveSpeed(this.u))
    set old = GetUnitMoveSpeed(this.u)
    // old = 330

    set r = old - 50
    // r = 330 - 50 = 280

    call SetUnitMoveSpeed(this.u, r)
    set new = GetUnitMoveSpeed(this.u)
    // new = 280 * 1.1 = 308

    set r = (r - ((new - old) / new) * r) - 50
    // r = (280 - ((308 - 330) / 308) * 280) - 50
    // r = (280 - (-22 / 308) * 280) - 50
    // r = (280 - (-20)) - 50
    // r = 300 - 50
    // r = 250

    call SetUnitMoveSpeed(this.u, r)
endmethod


As you can see, the above works fine. Since Unit's speed is set to 250, the actual Unit's MS would be 275 (250 * 1.1). Thus, now my code works fine for % MS factor cases.

Now there's one final problem. Whenever my new variable exceeds 522, the value returned is always 522. I'm guessing this is due to the fact that WC3 has the 522 limitation. So by theory, if my new SHOULD be 600, it always remain as 522. Is there a way to solve this? Thanks!
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
im not sure how to get the speed working better for under 522, but X-Speed is a mod that was around for a long time (cant find it now so no link :() that would be able to increase the movespeed of the unit by (using t32 i think) setting their x/y based on where they moved in that time and it was very acurate for managing unit's movespeed
 

Dirac

22710180
Reaction score
147
im not sure how to get the speed working better for under 522, but X-Speed is a mod that was around for a long time (cant find it now so no link :() that would be able to increase the movespeed of the unit by (using t32 i think) setting their x/y based on where they moved in that time and it was very acurate for managing unit's movespeed

Increasing the unit's movement speed through triggers is a bad idea.
Reason: The unit's facing doesn't turn fast enough to handle the "new" speed above 522, sometimes units would start to spin into circles when they're moving.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i dont really understand how that would be unless they are jumping way past their target but if the frequency is high enough and the interval low enough and you didnt have some rediculously high movement speed it wouldnt do that enough to truly matter, maybe a single turn around once in a while but nothing huge, and i dont remember that happening once with x-speed when i used it

it worked by setting them forward a minimal ammount (1 range point for every speed point above 522 every second, divided by 32 times/sec)
at 1k movespeed (very common used speed for missles) the total it moved forward in jump was 15 distance which is still in the range to complete an action (i believe, dont quote me on it)
 

Dirac

22710180
Reaction score
147
it worked by setting them forward a minimal ammount (1 range point for every speed point above 522 every second, divided by 32 times/sec)
That's how does system works, and that's exactly what causes the bug.
We won't be able to do this correctly until Nestharus develops a "route-tracing" system to handle the creation of points at edges among unpathable blocks between two points.
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
funny how you say there is a bug, although when i was using the system after hours of playing i didnt encounter it one time...
how does this cause a bug when the unit merely has to be in range of the point (the size of the unit counts as the unit, but the center of its diameter is the unit's point)
i tested that a few different ways and it seemed to be correct
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
It does it at higher speed values. For most practical applications, it should work just fine. (usually up to values around 1000) Once the speed gets too high, however, it will skip over. You can fix it by changing the interval and whatnot, as you said, but it takes a hit on performance.

But it will still work fine, I don't think that another system would need to be made to fix that problem. ;)
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
what about if it used PlayerUnitEvent along with the system and recorded each unit that it moved and their distance from their target, and only moved them if they were out of a certain range from their target
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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