JeViCo Posted April 25, 2018 Share Posted April 25, 2018 Hello everyone! How can i work with vehicle parts elements? For example i want to focus player's camera on certain part. Also i want to attach other objects to vehicle part without using custom model's offsets. Any ideas? Link to comment
Moderators IIYAMA Posted April 26, 2018 Moderators Share Posted April 26, 2018 They are not mta elements. But there are functions that can get the position and rotation of them. I am very sure that you have already found them. Find them if you haven't! ......... ............. ........... .............. .......... After that. The function getElementMatrix can help you with the vehicle orientation. https://wiki.multitheftauto.com/wiki/GetElementMatrix And on that same page there is something that creates a matrix the same way as the function above. But gives you also the ability to get the matrix without using an actual element. (Last example) function getElementMatrix(element) local rx, ry, rz = getElementRotation(element, "ZXY") rx, ry, rz = math.rad(rx), math.rad(ry), math.rad(rz) local matrix = {} matrix[1] = {} matrix[1][1] = math.cos(rz)*math.cos(ry) - math.sin(rz)*math.sin(rx)*math.sin(ry) matrix[1][2] = math.cos(ry)*math.sin(rz) + math.cos(rz)*math.sin(rx)*math.sin(ry) matrix[1][3] = -math.cos(rx)*math.sin(ry) matrix[1][4] = 1 matrix[2] = {} matrix[2][1] = -math.cos(rx)*math.sin(rz) matrix[2][2] = math.cos(rz)*math.cos(rx) matrix[2][3] = math.sin(rx) matrix[2][4] = 1 matrix[3] = {} matrix[3][1] = math.cos(rz)*math.sin(ry) + math.cos(ry)*math.sin(rz)*math.sin(rx) matrix[3][2] = math.sin(rz)*math.sin(ry) - math.cos(rz)*math.cos(ry)*math.sin(rx) matrix[3][3] = math.cos(rx)*math.cos(ry) matrix[3][4] = 1 matrix[4] = {} matrix[4][1], matrix[4][2], matrix[4][3] = getElementPosition(element) matrix[4][4] = 1 return matrix end With this matrix you can attach stuff with a render event. Of course I understand that it might look a little bit complex. But it is really the only way without doing very complex calculations. 1 Link to comment
Scripting Moderators thisdp Posted April 26, 2018 Scripting Moderators Share Posted April 26, 2018 5 hours ago, IIYAMA said: They are not mta elements. But there are functions that can get the position and rotation of them. I am very sure that you have already found them. Find them if you haven't! ......... ............. ........... .............. .......... After that. The function getElementMatrix can help you with the vehicle orientation. https://wiki.multitheftauto.com/wiki/GetElementMatrix And on that same page there is something that creates a matrix the same way as the function above. But gives you also the ability to get the matrix without using an actual element. (Last example) function getElementMatrix(element) local rx, ry, rz = getElementRotation(element, "ZXY") rx, ry, rz = math.rad(rx), math.rad(ry), math.rad(rz) local matrix = {} matrix[1] = {} matrix[1][1] = math.cos(rz)*math.cos(ry) - math.sin(rz)*math.sin(rx)*math.sin(ry) matrix[1][2] = math.cos(ry)*math.sin(rz) + math.cos(rz)*math.sin(rx)*math.sin(ry) matrix[1][3] = -math.cos(rx)*math.sin(ry) matrix[1][4] = 1 matrix[2] = {} matrix[2][1] = -math.cos(rx)*math.sin(rz) matrix[2][2] = math.cos(rz)*math.cos(rx) matrix[2][3] = math.sin(rx) matrix[2][4] = 1 matrix[3] = {} matrix[3][1] = math.cos(rz)*math.sin(ry) + math.cos(ry)*math.sin(rz)*math.sin(rx) matrix[3][2] = math.sin(rz)*math.sin(ry) - math.cos(rz)*math.cos(ry)*math.sin(rx) matrix[3][3] = math.cos(rx)*math.cos(ry) matrix[3][4] = 1 matrix[4] = {} matrix[4][1], matrix[4][2], matrix[4][3] = getElementPosition(element) matrix[4][4] = 1 return matrix end With this matrix you can attach stuff with a render event. Of course I understand that it might look a little bit complex. But it is really the only way without doing very complex calculations. why not use oop? https://wiki.multitheftauto.com/wiki/Matrix 1 Link to comment
Moderators IIYAMA Posted April 27, 2018 Moderators Share Posted April 27, 2018 17 hours ago, thisdp said: why not use oop? https://wiki.multitheftauto.com/wiki/Matrix Because I am not asking the user to learn also oop and everything is already available on that page. 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