Z4Zy Posted September 22, 2018 Share Posted September 22, 2018 Hello friends ! Aren't there any easy way to get the offset position of X, Y and Z of an attaching element, that can be used as "attachElements" function's arguments ? Please tell me a way if you know. 1 Link to comment
Addlibs Posted September 22, 2018 Share Posted September 22, 2018 Have you read attachElementsOffsets (it's linked in the attachElements wiki page)? Maybe something in there will help. 1 1 Link to comment
Moderators IIYAMA Posted September 22, 2018 Moderators Share Posted September 22, 2018 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 1 Link to comment
Z4Zy Posted September 22, 2018 Author Share Posted September 22, 2018 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 IIYAMA Posted September 22, 2018 Moderators Share Posted September 22, 2018 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. 1 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