JAY.ANN Posted July 1, 2022 Share Posted July 1, 2022 Is there a way to calculate vehicle's speed along it's X or Y local axis? I would like to make a recoil system for transport. Thank you for your attention! Link to comment
Moderators IIYAMA Posted July 2, 2022 Moderators Share Posted July 2, 2022 16 hours ago, JAY.ANN said: Is there a way to calculate vehicle's speed along it's X or Y local axis? Normally you would get the direction vector X, Y: https://wiki.multitheftauto.com/wiki/Vector/Vector2 And get the length of it: .getLength() / .length This is the 3D variant (useful function): https://wiki.multitheftauto.com/wiki/GetElementSpeed And this would be the 2D variant: local speedX, speedY = getElementVelocity(theElement) -- element speed local speed = Vector2(speedX, speedY).length -- get the direction vector > get .length = direction speed Link to comment
JAY.ANN Posted July 2, 2022 Author Share Posted July 2, 2022 58 minutes ago, IIYAMA said: Normally you would get the direction vector X, Y: https://wiki.multitheftauto.com/wiki/Vector/Vector2 And get the length of it: .getLength() / .length This is the 3D variant (useful function): https://wiki.multitheftauto.com/wiki/GetElementSpeed And this would be the 2D variant: local speedX, speedY = getElementVelocity(theElement) -- element speed local speed = Vector2(speedX, speedY).length -- get the direction vector > get .length = direction speed I cannot implement the above, I don't know why It works incorrect - the speed sets only while the vehicle at moving. I guess I did something wrong. local speedX, speedY = getElementSpeed( veh ) local speed = Vector2( speedX, speedY ).length setElementSpeed( veh, 1, tonumber( speed - 0.1 ) ) Link to comment
Moderators IIYAMA Posted July 2, 2022 Moderators Share Posted July 2, 2022 10 hours ago, JAY.ANN said: I guess I did something wrong. https://wiki.multitheftauto.com/wiki/GetElementSpeed Quote This function returns a number containing the element's speed if the arguments provided are valid. It returns nil plus an error otherwise. This useful function returns 1 speed value (based on x, y, z) What I explained is how the useful function works and how you can change it more or less from 3D(x,y,z) to 2D(x,y). Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now