Notifications
Clear all
[Closed] Scripting object pos wrt linked objects
Aug 08, 2008 2:17 pm
Here is the scenario:
I have two boxes (a,b) linked to a pyramid. I want a third box to position itself between the two boxes at an offset (say 10) and to maintain that offset irrespective of the positions of a & b (always perpendicular to a & b).
My Approach:
I had a position script on the third box
offset=30
RefX=(TopNode.pos.x-BotNode.pos.x)/2
RefY=(TopNode.pos.y-BotNode.pos.y)/2
RefZ=(TopNode.pos.z-BotNode.pos.z)/2
VTilt=atan(RefY/RefZ)
Htilt=atan(RefX/RefY)
if (BotNode.pos.z>TopNode.pos.z) then
(
TargX=TopNode.pos.x-RefX-((offset*cos(Htilt))*sin(Htilt))
TargY=TopNode.pos.y-RefY+((offset*cos(Vtilt))*cos(Htilt))
TargZ=TopNode.pos.z-RefZ-(offset*sin(Vtilt))
) else
(
TargX=TopNode.pos.x-RefX-((offset*cos(Htilt))*sin(Htilt))
TargY=TopNode.pos.y-RefY-((offset*cos(Vtilt))*cos(Htilt))
TargZ=TopNode.pos.z-RefZ+(offset*sin(Vtilt))
)
[TargX,TargY,TargZ]
The Problem:
The code works as long as the Pyramid is not rotated. At 180degrees rotation (of the pyramid), the third box flips facing the wrong side. I have tried using the “in coordsys local context” to compute the trignometrical changes in [x,y,z]– I have not succeeded. Can anyone give me some ideas? See attached screenshots for the setup.
1 Reply