Code_Man Posted July 12, 2018 Share Posted July 12, 2018 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? Quote Link to comment Share on other sites More sharing options...
Happenstance Posted July 13, 2018 Share Posted July 13, 2018 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. Quote Link to comment Share on other sites More sharing options...
OTHGMars Posted July 13, 2018 Share Posted July 13, 2018 Check out the VectorLen function https://github.com/GarageGames/Torque3D/blob/development/Engine/source/math/mathTypes.cpp#L937-L962. It's not the sum of the axes components, but will give you the speed of a velocity vector. Quote Link to comment Share on other sites More sharing options...
Code_Man Posted July 13, 2018 Author Share Posted July 13, 2018 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. Quote Link to comment Share on other sites More sharing options...
Happenstance Posted July 13, 2018 Share Posted July 13, 2018 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. Quote Link to comment Share on other sites More sharing options...
Timmy Posted July 14, 2018 Share Posted July 14, 2018 As others have said above, the length(magnitude) of the velocity vector is the speed. Quote Link to comment Share on other sites More sharing options...
Code_Man Posted July 24, 2018 Author Share Posted July 24, 2018 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.