Jump to content

Position offset of a car


Karuzo

Recommended Posts

  • Moderators
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 
  
addCommandHandler("getThisPart", 
function () 
    local vehicle = getPedOccupiedVehicle ( localPlayer ) 
    if vehicle then 
        local x,y,z = getPositionFromElementOffset(vehicle,0,0,10)-- offset x,y,z  
    end 
end) 
  
  

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

Link to comment

Hey,

I just tried that function and i have a problem now.

If i create the object(which i want to attach to the car) without attaching it to the car, it is on the position where i want it.

But if i create it and attach it right after that, the position is different and i can't even see the object.

This is my code:

  
    addCommandHandler("t", 
    function () 
        local vehicle = getPedOccupiedVehicle ( localPlayer ) 
        if vehicle then 
            local x,y,z = getPositionFromElementOffset(vehicle,0,3,0) 
            local rx,ry,rz = getElementRotation(vehicle) 
            element = createObject(1060,x,y,z,rx,ry,rz,false) 
            outputDebugString("XYZ:"..x..","..y..","..z) 
            outputDebugString("RXRYRZ:"..rx..","..ry..","..rz) 
            attachElements(element,vehicle,x,y,z)  
        end 
    end) 

Link to comment

Not sure if it's work perfect

function getVehicleHeight(veh) 
 if ( isElement(veh) and getElementType(veh) == "vehicle" ) then 
 local x,y,z = getElementPosition(veh) 
 local a = 0 
  while ( not isLineOfSightClear(x,y,z+a-0.1,x,y,z+a,false,true,false,false,false) ) do 
   a = a + 0.1 
  end 
  return a 
 end 
 return false 
end 

local x,y,z = getElementPosition(vehicle) 
local x = getVehicleHeight(veh) 
local Height = x+z 

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