# Getting velocity sum

## Recommended Posts

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?

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

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.

##### Share on other sites

As others have said above, the length(magnitude) of the velocity vector is the speed.

##### Share on other sites

• 2 weeks later...

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?

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• #### Games

• Discord
×
• Create New...