joedajoester Posted November 20, 2011 Share Posted November 20, 2011 How do i calculate offset for attachElements? https://wiki.multitheftauto.com/wiki/AttachElements Link to comment
mcB Posted November 20, 2011 Share Posted November 20, 2011 attachElements ( arrowMarker, theVehicle, 0, 1, 0.5 ) That would be the offset from the car, if im correct Link to comment
myonlake Posted November 20, 2011 Share Posted November 20, 2011 Actually it's pretty easy. I made this with my phone and I just woke up, but test this, it should be like this. I'll fix the errors when I get on mah computah. local object1 = createObject(1337, 110, 200, 10) local object2 = createObject(1337, 100, 205, 10) function attaching() local x, y, z = getElementPosition(object1) attachElements(object2, object1, 100 - x, 205 - y, 10 - z) end addCommandHandler("attach", attaching) Link to comment
unknooooown Posted November 20, 2011 Share Posted November 20, 2011 I think he is talking about calculating the distance between two objects that have already been attached. I could be wrong, but I am gonna post an example of what I think he wants anyways Maybe someone else can use it if they come across the post x1,y1,z1 = 10,10,10 x2,y2,z2 = 30,30,30 outputChatBox(x1-x2..","..y1-y2..","..z1-z2) That would return: -20,-20,-20 You can also use the function getDistanceBetweenPoints3D https://wiki.multitheftauto.com/wiki/Get ... enPoints3D x1,y1,z1 = getElementPosition(obj1) x2,y2,z2 = getElementPosition(obj2) distance = getDistanceBetweenPoints3D(x1,y1,z1,x2,y2,z2) outputChatBox("Distance between 'obj1' & 'obj2' is: "..distance) Link to comment
joedajoester Posted November 23, 2011 Author Share Posted November 23, 2011 Thank you all, Wafamde was exactly what i wanted but if i create object at coordinates, 0, 0, 0 and the offset would be the coordinates of the object Link to comment
karlis Posted November 23, 2011 Share Posted November 23, 2011 function calculateOffsets(slaveElement, masterElement) local px, py, pz = getElementPosition(slaveElement) local vx, vy, vz = getElementPosition(masterElement) local sx = px - vx local sy = py - vy local sz = pz - vz local rotpX, rotpY, rotpZ = getElementRotation(slaveElement) local rotvX,rotvY,rotvZ = getElementRotation(masterElement) local t = math.rad(rotvX) local p = math.rad(rotvY) local f = math.rad(rotvZ) local ct = math.cos(t) local st = math.sin(t) local cp = math.cos(p) local sp = math.sin(p) local cf = math.cos(f) local sf = math.sin(f) local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy local y = st*sz - sf*ct*sx + cf*ct*sy local rotX = rotpX - rotvX local rotY = rotpY - rotvY local rotZ = rotpZ - rotvZ return x, y, z, rotx, roty, rotz end taken from soem glue resource and slightly modified. 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