[Closed] Sliding joint script help
I’m trying to make a rig with a sliding joint, where a helper slides along a shaft.
I’ve got something working, but I need to connect it to a larger rig, and when I do, it breaks.
I need to be able to connect it at any point in a hierarchy.
When using the distance function I would like to use world positions, but to avoid a loop I’ve had to use
P3.controller.Position instead of P3.pos, which would give me world positions.
Grateful for any help.
Sliding_joint_05.max (496 KB)
This code is on a rotation script controller:
fn measureAngle a b c =
(
v1=b-a
v2=c-a
n1=normalize v1
n2=normalize v2
angle=acos (dot n1 n2)
)
P1pos=P1.controller.Position
P2pos=P2.controller.Position
P3pos=P3.controller.Position
P4pos=P4.controller.Position
P3parpos=P3.parent.controller.Position
adist=distance P1pos P2pos
bdist=distance P2pos (P3parpos-P3pos)
P1P2pos=[P1pos[1],P1pos[2],P2pos[3]]
Aang=measureAngle P1pos P4pos P2pos
Aangl=measureAngle P2pos P1P2pos P1pos
Cang=asin((sin(Aang)*adist)/bdist)
Bang=180-Aang-Cang
rota=180-Aangl-Bang
EulerToQuat (eulerAngles 0 rota 0)