Jump to content

Calculate Offset positions of X, Y and Z of an attaching element


Z4Zy

Recommended Posts

  • Moderators
9 minutes ago, DeadthStrock said:

offset position

With the matrix of course: (the offset can be received with the function in @MrTasty his replied)

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

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

or

https://wiki.multitheftauto.com/wiki/Matrix

  • Thanks 1
Link to comment
2 hours ago, IIYAMA said:

With the matrix of course: (the offset can be received with the function in @MrTasty his replied)


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

 

 Hey buddy !

          The code you've mentioned is return the world position of the element. But I want to return the offset positions of the element relevant to the attached-to element. Can you ?

Link to comment
  • Moderators

Just to be clear:

Offset position = a world position (which is calculated by an offset value)

Offset = a distance value (not a position)

 

To calculate offset from two positions:

Position:1 [435, 6577, 3457]

position:2 [325, 7657, 5686]

(Position:1 [435, 6577, 3457]) - (position:2 [325, 7657, 5686]) = offset:1

(position:2 [325, 7657, 5686]) - (Position:1 [435, 6577, 3457]) = offset:2

 

The main issue is of course if getElementPosition doesn't work on attached elements.(which I would consider as a MTA bug, but afaik they fixed this...) < If this function doesn't work correctly and the rotation in attachElements is used, it will be indeed a bit complex and getPositionFromElementOffset will not be helpful.

 

 

 

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