myonlake Posted October 27, 2011 Share Posted October 27, 2011 (edited) Hello, I am trying to find a script that automaticly positions my createObjects to attachElements so that I don't need to configure them myself. It's annoying when you need to position every object, takes a lot of time. EDIT: I solved the problem Alright, so the fix is that when you do attachElements, you MINUS the position from the original position of the source object. Like this. local originalX = 100 local originalY = 100 local originalZ = 1 local example1 = createObject... local example2 = createObject... attachElements(example1, example2, 1000 - originalX, 1000 - originalY, 5 - originalZ) Edited May 30, 2019 by myonlake Link to comment
karlis Posted October 27, 2011 Share Posted October 27, 2011 know its solved, but i believe this is more of a solution(as rotation changes the axis direction) 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 note:taken from old glue resource 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