lcd1232 Posted August 31, 2014 Share Posted August 31, 2014 I have problem with getComponentPosition. I want to find coordinates of vehicle's part, but it doesn't work. Here code: addCommandHandler("getposit", function () --getPositionFromElementOffset = exports.functions:getPositionFromElementOffset local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) local vx,vy,vz = getElementPosition( theVehicle ) local cx,cy,cz = getVehicleComponentPosition( theVehicle, 'bump_rear_dummy' ) local vfx,vfy,vfz = getElementRotation( theVehicle ) local result = 'vx = '..vx..' vy = '..vy..' vz = '..vz outputDebugString( result ) result = 'cx = '..cx..' cy = '..cy..' cz = '..cz outputDebugString( result ) result = 'vfx = '..vfx..' vfy = '..vfy..' vfz = '..vfz outputDebugString( result ) local zx, zy, zz = exports.functions:getPositionFromElementOffset( theVehicle, cx, cy, cz ) --local zx, zy, zz = call( getResourceFromName( 'functions' ), 'getPositionFromElementOffset', theVehicle, 0, 4, 0 ) createColSphere( zx, zy, zz, 1 ) end ) getPositionFromElementOffset: function getPositionFromElementOffset( theElement, offX, offY, offZ ) local m = getElementMatrix ( theElement ) -- 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 Result: http://s010.radikal.ru/i312/1408/4b/7f3906e25539.png Link to comment
./BlackBird# Posted August 31, 2014 Share Posted August 31, 2014 addCommandHandler("getposit", function () --getPositionFromElementOffset = exports.functions:getPositionFromElementOffset local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) local vx,vy,vz = getElementPosition( theVehicle ) local cx,cy,cz = getVehicleComponentPosition( theVehicle, 'bump_rear_dummy' ) local vfx,vfy,vfz = getElementRotation( theVehicle ) local result = 'vx = '..vx..' vy = '..vy..' vz = '..vz outputDebugString( result ) result = 'cx = '..cx..' cy = '..cy..' cz = '..cz outputDebugString( result ) result = 'vfx = '..vfx..' vfy = '..vfy..' vfz = '..vfz outputDebugString( result ) local zx, zy, zz = vx+cx,vy+cy,vz+cz --local zx, zy, zz = call( getResourceFromName( 'functions' ), 'getPositionFromElementOffset', theVehicle, 0, 4, 0 ) createColSphere( zx, zy, zz, 1 ) end ) Link to comment
lcd1232 Posted September 1, 2014 Author Share Posted September 1, 2014 it doesn't work because vehicle have rotation Link to comment
./BlackBird# Posted September 2, 2014 Share Posted September 2, 2014 addCommandHandler("getposit", function () --getPositionFromElementOffset = exports.functions:getPositionFromElementOffset local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) local vx,vy,vz = getElementPosition( theVehicle ) local cx,cy,cz = getVehicleComponentPosition( theVehicle, 'bump_rear_dummy' ) local vfx,vfy,vfz = getElementRotation( theVehicle ) local result = 'vx = '..vx..' vy = '..vy..' vz = '..vz outputDebugString( result ) result = 'cx = '..cx..' cy = '..cy..' cz = '..cz outputDebugString( result ) result = 'vfx = '..vfx..' vfy = '..vfy..' vfz = '..vfz outputDebugString( result ) local col = createColSphere( vx,vy,vz, 1 ) attachElements(col,theVehicle,cx,cy,cz) end ) Link to comment
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