### Getting velocity sum

There are no stupid questions, just stupid answers.

#### Getting velocity sum

Code_Man
Posts: 66
Joined: Fri Jan 26, 2018 9:12 pm
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

Happenstance
Posts: 104
Joined: Sat Apr 11, 2015 9:08 pm
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

OTHGMars
Posts: 30
Joined: Fri Jul 14, 2017 2:19 am
Check out the VectorLen function https://github.com/GarageGames/Torque3D ... #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

Code_Man
Posts: 66
Joined: Fri Jan 26, 2018 9:12 pm
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

Happenstance
Posts: 104
Joined: Sat Apr 11, 2015 9:08 pm
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

Timmy
Posts: 378
Joined: Thu Feb 05, 2015 3:20 am
As others have said above, the length(magnitude) of the velocity vector is the speed.

#### Re: Getting velocity sum

Code_Man
Posts: 66
Joined: Fri Jan 26, 2018 9:12 pm
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?

#### Who is online

Users browsing this forum: Google [Bot] and 10 guests