Jump to content

getPostionInFrontOfElement


Atton

Recommended Posts

  • Moderators

https://wiki.multitheftauto.com/wiki/GetElementMatrix

  
function getPositionFromElementOffset(element,offX,offY,offZ) 
    local m = getElementMatrix ( element )  -- Get the matrix 
    local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1]  -- Apply transform 
    local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2] 
    local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3] 
    return x, y, z                               -- Return the transformed point 
end 
  
  
-- Get the position of a point 2 units in front of the element: 
x,y,z = getPositionFromElementOffset(element,0,2,0) 
  
  
  

Link to comment

IIYAMA code works only client side (getElementMatrix)

This function works client side & server side, I didn't made it but JR10 posted it once.

function getPositionInfrontOfElement ( element , meters ) 
    if not element or not isElement ( element ) then 
        return false 
    end 
    if not meters then 
        meters = 3 
    end 
    local posX , posY , posZ = getElementPosition ( element ) 
    local _ , _ , rotation = getElementRotation ( element ) 
    posX = posX - math.sin ( math.rad ( rotation ) ) * meters 
    posY = posY + math.cos ( math.rad ( rotation ) ) * meters 
    return posX , posY , posZ 
end 

Usage:

local x,y,z = getPositionInfrontOfElement ( element , meters )

element = the element's position you want to get in front off

meters = how many units from the element it needs to check

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...