Page 1 of 1

Getting velocity sum

Posted: Fri Jul 13, 2018 1:20 am
by Code_Man
I have a little odd problem, i try to get the absolute sum of all fields from velocity, the speed so speak.
However when i get an output that looks like "00" or "x.z.y" where x y and z are numbers when i use the following code.

%v = %obj.getVelocity();
echo(mAbs(getWord(%v, 0)) + mAbs(getWord(%v, 1)) + mAbs(getWord(%v, 2)));

I dont know whats wrong and is there some kind of function builtin perhaps to save me the code mess?

Re: Getting velocity sum

Posted: Fri Jul 13, 2018 2:13 am
by Happenstance
Can you post a snippet or screenshot of the console log to show the problem? I just tried calling the above on a bunch of random velocities but couldn't reproduce the problem.

Also, what're you using the above code for? Might help figuring out what's happening.

Re: Getting velocity sum

Posted: Fri Jul 13, 2018 3:12 am
by OTHGMars
Check out the VectorLen function ... #L937-L962. It's not the sum of the axes components, but will give you the speed of a velocity vector.

Re: Getting velocity sum

Posted: Fri Jul 13, 2018 7:12 pm
by Code_Man
I need the speed of the player to implement weapon accuracy modifiers based on it.

The code i posted is the very one i am using in a function that gets scheduled every second once player spawns, %obj is the player in this case.

Since there is no other callback function that i can check if the player is moving i probably rely on this method.

I also noticed there is no "walking" pose in getpose(), i dont exactly know what pose is meant to represent, but its odd there is a sprint pose but no moving pose.
Perhaps in the future it should be extended to cover player movement.

Cant post the whole thing right now cuz its on my other pc.

Im not much of a math person, im not sure if vectorlen is what i really want but i suppose it should be close enough, can adjust it later if need be.

Re: Getting velocity sum

Posted: Fri Jul 13, 2018 9:35 pm
by Happenstance
Sounds like VectorLen() is what you're looking for. I believe 'speed' is just the magnitude of a velocity vector, which is what VectorLen returns, and will always be a positive number.

Re: Getting velocity sum

Posted: Sat Jul 14, 2018 8:30 am
by Timmy
As others have said above, the length(magnitude) of the velocity vector is the speed.

Re: Getting velocity sum

Posted: Tue Jul 24, 2018 8:34 pm
by Code_Man
Bad news, seems that just setRotation actually changes velocity even when i remain in the same spot.

Not sure how to work my way around this other than implement my own kind of velocity check that accounts for differences in position only.

What the hell is going on here?
Any alternative suggestions?