MTA.Castiel Posted November 14, 2022 Posted November 14, 2022 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 )
Shady1 Posted November 14, 2022 Posted November 14, 2022 (edited) 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 November 14, 2022 by Shady1 1 1
MTA.Castiel Posted November 14, 2022 Author Posted November 14, 2022 Thats perfect, many thanks Shady.
Shady1 Posted November 14, 2022 Posted November 14, 2022 you're welcome, if you have any other requests, all you have to do is open a new topic and tag me
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