Jump to content

offset


joedajoester

Recommended Posts

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

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 :P

Maybe someone else can use it if they come across the post :D

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

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