Jump to content

Distance to ground


MTA.Castiel

Recommended Posts

Hi there, ? how do we calculate the distance from a player to the ground? - In this case for example, we're flying a helicopter so the ground may be anything below us such as the roof top of a tall building or a mountain top or a hill. 

In the example code below when i output the 'z' coordinate it doesn't compensate for anything else below the player, rather acts as a measurement of how high or low i seem to be from 0 (water level).

 

function outputGroundDis ( )

	local x, y, z = getElementPosition ( localPlayer )
	outputChatBox ( math.floor ( z ) )

	if math.floor ( z ) == 100 then
		--triggerEvent ( "heightWarning", localPlayer )
		outputChatBox ( "event triggered" )
	end
end
setTimer ( outputGroundDis, 1000, 0 )

 

Link to comment

hello @MTA.Castiel 
Get ground coordinates with getGroundPosition
GetDistancePointBetween3D
to find distance.

addCommandHandler("distanceground",
    function()
       local px, py, pz = getElementPosition(localPlayer)
       local groundPosition = getGroundPosition(px, py, pz)
       local distanceGround = getDistanceBetweenPoints3D(px, py, pz, px, py, groundPosition)
       outputDebugString("distance ground:"..distanceGround)
    end
)

you can do a test run

Edited by Shady1
  • Like 1
  • Thanks 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...