I want to make some lights with a retractable beam: the beam is minimized and centered into the root prim when inactive. The light can rotate while the beam is active or not, and I want only one script in the root prim to control the beam.
FIXED: do not apply any rotation! In fact, when setting PRIM_POS_LOCAL, it seems OpenSim also computes the offset due to root rotation.
Here is a picture of the action:
The active size of the beam is saved before it's hidden, so it can be used when restoring it. I tried several methods without success. For me, this one was the right one:
integer BEAM_LINK = 2
// returns the new local position of the beam from its stored size
vector restoreBeam(vector beamSize) {
vector rootSize = llGetScale();
rotation rootRot = llGetRot();
// calculate the offset from a "zero-rotation" root prim
vector beamOffset = <0.0, 0.0, rootSize.z / 2 + beamSize.z / 2>;
// the wanted beam position relative to the root
// this is simplified considering the beam has a zero rotation relative to the root
vector beamPos = beamOffset * rootRot;
}All is ok as long are there is no rotation, but as soon as there is one, here is the result:
I tried several other formulas, like converting first to region coordinates, applying the rotation, then removing the root position from the result.


Let me know if this is what you're looking for!