Jump to content

calculate way meters


fairyoggy

Recommended Posts

  • Moderators
32 minutes ago, slapztea said:

How can I calculate the meters traveled?

For example, a player got in a car and drove 100 meters and this "100" save in elementData.

I tried to work with it, but I don’t understand how to implement it correctly.

 

 

Just compare the distance between positions of the vehicle.

So you get the position.

And you wait with a delay.

And then you get the position again.

Now you can calculate the distance between them with:

https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints2D

https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D

 

 

Just like a GPS does it's thing.

  • Like 1
Link to comment
27 minutes ago, IIYAMA said:

 

Just compare the distance between positions of the vehicle.

So you get the position.

And you wait with a delay.

And then you get the position again.

Now you can calculate the distance between them with:

https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints2D

https://wiki.multitheftauto.com/wiki/GetDistanceBetweenPoints3D

 

 

Just like a GPS does it's thing.

ok, I understood how to implement this in your way. But if we consider from the point of view of comparing the speed of a car?

if it is used only for cars and that there was a check for speed, and not for two coordinates. How to implement this?

Link to comment
  • Moderators
11 hours ago, slapztea said:

But if we consider from the point of view of comparing the speed of a car?

Hmm speed. It can be used. But it will be less accurate, because you are making assumptions about the future.

> You do not know how far your car will have driven in the future. For example you hit the wall or another car.

 

 

local previousVelocity
addEventHandler("onClientPreRender", root, 
function (timeSlice) 
	local vehicle = getPedOccupiedVehicle ( localPlayer )
	if vehicle then
		if previousVelocity then
			local travelDistance = getDistanceBetweenPoints3D(0,0,0, previousVelocity[1], previousVelocity[2], previousVelocity[3]) -- 1/50 of a second
			-- here you have to do something with timeSlice (which is the time between the [now] frame and [last] frame) and the speed...
			-- maybe: 1000 / 50 = 20 ??????????????
			dxDrawText(travelDistance / 20 * timeSlice, 300,300 )
		end
		local vX, vY, vZ = getElementVelocity(vehicle)
		previousVelocity = {vX, vY, vZ}
	end
end)

You still will have to test that with the position method.

  • Like 1
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...