If I didnt miss anything, at the moment the only way to get a units speed is Spring.GetUnitVelocity which returns a vector.
So to get the unitspeed as a number, you have to calculate the length of this vector.
But there is still no way to know if the unit is driving forwards or backwards. Beside maybe comparing the speed vector with the heading vector. (checking if they point in same direction)
This seems like a bit of unnessecaty calculations and iam not sure how accurate it would because you would have to do it at intervalls.
Knowing forward/backward movement is important for animations ie reverse walking animations or spin wheels backwards.
So I think it would be good to have:
Spring.GetUnitSpeed (unitID)
it would return the unit speed as a number, compatible to the numbers in unitdef and if the unit is driving backwards it is negative.
In unit animation scripts there are the StartMoving() and StopMoving() callins.
Maybe these callins could also include the units speed and the units wanted speed.
So that you do not have to GetUnitSpeed and do not have to poll the speed in a loop to check for changes.
Similiar to how to
script.WindChanged ( number heading, number strength )
also includes heading+strength even though there is Spring.GetWind () too.
getting unit speed/direction beside GetUnitVelocity
Moderator: Moderators
Re: getting unit speed/direction beside GetUnitVelocity
It seems like the only thing that would do is take the dot product of the velocity vector and the heading vector (as I believe the heading vector is a unit vector). Is that not something you could do yourself?
Re: getting unit speed/direction beside GetUnitVelocity
WRT: The direction of travel, you can use get REVERSING in cob (Or using Spring.GetUnitCOBValue in a gadget or the LUS alternative, Spring.UnitScript.GetUnitValue) where REVERSING is 109.
Re: getting unit speed/direction beside GetUnitVelocity
ILMTitan:
thats what i'd done otherwise yes.
FLOZi:
ah thanks, thats good. had only searched for "reverse" and "backwards" which does not find "REVERSING."
Still think that GetUnitSpeed would be nice to have because it atm still requires to calculate the speed vector's length to get absolute speed and then use the REVERSING cob thing for direction.
It is not too bad but seems a bit cumbersome for something so basic.
thats what i'd done otherwise yes.
FLOZi:
ah thanks, thats good. had only searched for "reverse" and "backwards" which does not find "REVERSING."
Still think that GetUnitSpeed would be nice to have because it atm still requires to calculate the speed vector's length to get absolute speed and then use the REVERSING cob thing for direction.
It is not too bad but seems a bit cumbersome for something so basic.
Re: getting unit speed/direction beside GetUnitVelocity
So GetUnitVelocity will return vx,vy,vz, length in future versions?
Nice :)
Nice :)