Here you go. This is a T shape. I've worked out that when the base of my T is at 0,0,0 rotated 0,0,0 I want to move the top part of my T up by 4.5 and rotate it locally by 90 degrees to make it sit on top of the base of the T. So I just set it to the location and rotation of the base of the T, then perform those movements 'locally', then it always sits on top of the T.
fWidth# = GetDeviceWidth()
fHeight# = GetDeviceHeight()
SetDisplayAspect(fWidth#/fHeight#)
setsyncrate(0,0)
createlightdirectional(1,0,-1,1,255,255,255)
objTBase = createobjectbox(1,8,1)
setobjectcolor(objTBase,255,0,0,255)
objTTop = createobjectbox(1,5,1)
setobjectcolor(objTTop,0,255,0,255)
do
//Move base about
setobjectposition(objTBase,sin(timer()*50)*10,0,cos(timer()*50)*4)
setobjectrotation(objTBase,timer()*10,timer()*40,0)
//Orientate the top of our T so it always locates to base
//1 . Set to base position and rotation
setobjectposition(objTTop,getobjectx(objTBase),getobjecty(objTBase),getobjectz(objTBase))
setobjectrotation(objTTop,getobjectanglex(objTBase),getobjectangley(objTBase),getobjectanglez(objTBase))
//2. Do out location rotations and movements so it's where we want it to be, relative to the base
moveobjectlocaly(objTTop,4.5)
rotateobjectlocalx(objTTop,90)
setcameraposition(1,0,20,-15)
setcameralookat(1,0,4,0,0)
sync()
loop