Hello all who are reading this. My question is how do i make a speedometre for a specific unit, for example i have tried seting up a varible to track the unit property movement speed current but that only seems to display the units max speed and not its current, so basicly i want for a unit that is not moving to display 0 and when the unit does move the speedometre will update, however i would like it to be accurate down to a decimal point if possible, any ideas i have had are really inefficient so if anyone could help me out with this i would appreciate it.
Well, current movement speed is the current maximum movement speed with any buffs etc factored in, the one displayed in the UI. To track the actual movement of the unit, the only way I know of is saving the last location of the unit in a specific interval and calculate the distance to the current location of the unit.
If this is one of the inefficient ideas you are referring to, I can assure you, tracking the speed this way for a couple of units is nothing to worry about, if done correctly.
Units have acceleration so it should be possible to create a variable speed.
Anyway, I would set up a real/fixed variable and run a while-loop forever. In this loop I would calculate the time and distance difference from the last iteration and use that to calculate a speed (distance/time). It would only render an interesting result if you use buffs or a low acceleration.
Speed is just a measurement of the distance traveled in a particular amount of time. In other words, speed equals the distance traveled divided by the time the travel took(If I travel 60 miles in one hour, I'm going 60 mph). So I would create a looping action defection that constantly updates a speed variable. For example:
// You create a GLOBAL variable (not local) which is a real array with enough indexes for each unit you need to track. //In this case, I'm treating it like each array index corresponds to the owner of the unit you're tracking. So Speed[2] is the speed of player 2, for example. // This is my action detentionOptions:CreateThreadParameters:MyUnit(Unit)LocalVars:Point1(Point),Point2(Point)Actions:Repeat(Forever){// Just in caseIf(MuUnitisalive)==false{// This is just in case you remove the unit or it dies at some point, we don't want this action to keep going by itself. break;}// The actual speed calculationSetPoint1=Positionofunit(MyUnit)wait0.2gametimesecondsSetPoint2=Positionofunit(MyUnit)// Now we update the speed variableSetMySpeedVariable[ownerofunit(MyUnit)]=[Distancebetweenpoints(Point1&Point2)/0.2]}
Once you make that action, just call it once for each unit you want to track the speed for. You can do whatever you want with that number- just display it on a dialog item, or do something crazy and actually create a speedometer needle, etc....
Hello all who are reading this. My question is how do i make a speedometre for a specific unit, for example i have tried seting up a varible to track the unit property movement speed current but that only seems to display the units max speed and not its current, so basicly i want for a unit that is not moving to display 0 and when the unit does move the speedometre will update, however i would like it to be accurate down to a decimal point if possible, any ideas i have had are really inefficient so if anyone could help me out with this i would appreciate it.
How are you modifying the unit's speed?
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Hello all who are reading this. My question is how do i make a speedometre for a specific unit, for example i have tried seting up a varible to track the unit property movement speed current but that only seems to display the units max speed and not its current, so basicly i want for a unit that is not moving to display 0 and when the unit does move the speedometre will update, however i would like it to be accurate down to a decimal point if possible, any ideas i have had are really inefficient so if anyone could help me out with this i would appreciate it.
Well, current movement speed is the current maximum movement speed with any buffs etc factored in, the one displayed in the UI. To track the actual movement of the unit, the only way I know of is saving the last location of the unit in a specific interval and calculate the distance to the current location of the unit.
If this is one of the inefficient ideas you are referring to, I can assure you, tracking the speed this way for a couple of units is nothing to worry about, if done correctly.
Units have acceleration so it should be possible to create a variable speed.
Anyway, I would set up a real/fixed variable and run a while-loop forever. In this loop I would calculate the time and distance difference from the last iteration and use that to calculate a speed (distance/time). It would only render an interesting result if you use buffs or a low acceleration.
Speed is just a measurement of the distance traveled in a particular amount of time. In other words, speed equals the distance traveled divided by the time the travel took(If I travel 60 miles in one hour, I'm going 60 mph). So I would create a looping action defection that constantly updates a speed variable. For example:
Once you make that action, just call it once for each unit you want to track the speed for. You can do whatever you want with that number- just display it on a dialog item, or do something crazy and actually create a speedometer needle, etc....
Validators can check for current speed I guess. So why not disable/enable buffs by using validators and then check for those buffs?
How are you modifying the unit's speed?