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.
  • 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 The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top