Jump to content

Calculating speed along the element's axis


JAY.ANN

Recommended Posts

  • Moderators
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
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
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...