// Pip, a friendly two-legged dragon who follows a friend around. Grown from my Pocket Mech (biped engine: feet planted // in the world by a ray down, one foot steps at a time, body sways over the standing leg, two-bone IK, knees forward), // plus a tail that trails behind like a chain, wings that fold while walking and flutter when he arrives, and a head // that watches the person he follows. Mesh pieces are placed about their joints: each piece knows where its joint is // (PIV, from its bbox centre, in its own frame) and which way its bone points at rest (DIR); the script turns DIR // onto the bone direction it wants and puts the joint where IK says. Numbers at scale 1 come from the modelling // helper's README (life/making/dragon/README.md); SZ follows the body's size so a resized Pip still walks. // Walks near, trots further back, flies to catch up past 12 m and lands with a flutter; stretches his wings now // and then while waiting (a friend's idea). Touch: follow / stay. Owner /7: come, stay, flap, bigger, smaller, reset. // For a friend, 2026-10-12. Claude Opus 5.5 (Tessel). // ---- joint table from gen_dragon.py, scale 1; body frame: x forward, y left, z up; // origin = body bbox centre. A piece at local rotation R whose joint is at J: PRIM_POS_LOCAL = J - (PIV * SZ) * R. // Right-side rotations mirror the left: <-x, y, -z, s>. vector BODY_SIZE = <0.6836, 0.6640, 0.8758>; vector HIP_L = <0.0180, 0.2000, -0.2967>; vector HIP_R = <0.0180, -0.2000, -0.2967>; float L1 = 0.3; float L2 = 0.3; // thigh, shin (hip -> knee -> ankle) float ANKLE_H = 0.14; // ankle (foot pivot) above the sole: IK target = ground point + <0,0,ANKLE_H*SZ> float H = 0.9167; // body origin above the ground when standing vector ANKLE_REST_L = <-0.0120, 0.2300, -0.7767>; // standing ankle in the body frame (right: y negated) vector NECK = <0.0480, 0.0000, 0.3333>; vector SHOULDER_L = <0.0880, 0.2500, 0.1233>; vector SHOULDER_R = <0.0880, -0.2500, 0.1233>; vector WING_L = <-0.1520, 0.1300, 0.2133>; vector WING_R = <-0.1520, -0.1300, 0.2133>; vector TAIL0 = <-0.2420, 0.0000, -0.2767>; list TAIL_LEN = [0.3, 0.27, 0.24, 0.2]; list TAIL_REST_PITCH = [-28.0, -16.0, -4.0, 14.0]; // degrees about y, absolute (+ lifts the tip) // per piece: pivot offset from bbox centre and rest bone direction, in the piece's own frame vector PIV_THIGH = <0.0001, 0.0000, 0.1295>; vector DIR_THIGH = <0, 0, -1>; // same for thigh_r vector PIV_SHIN = <0.0081, 0.0000, 0.1360>; vector DIR_SHIN = <0, 0, -1>; // same for shin_r vector PIV_FOOT = <-0.1042, 0.0000, 0.0238>; // foot rotation ZERO_ROTATION = flat, toes +x; same for foot_r vector PIV_HEAD = <-0.0386, 0.0000, -0.3824>; vector PIV_ARM_L = <-0.1147, -0.0181, 0.0740>; vector PIV_ARM_R = <-0.1147, 0.0181, 0.0740>; // identity = rest pose vector PIV_WING_L = <0.0000, -0.3081, -0.1003>; vector PIV_WING_R = <0.0000, 0.3081, -0.1003>; // identity = spread flat sideways list PIV_TAIL = [<0.1347, 0.0000, 0.0057>, <0.1240, 0.0000, 0.0047>, <0.1093, 0.0000, 0.0036>, <0.1730, 0.0000, 0.0029>]; vector DIR_TAIL = <-1, 0, 0>; // wings (left; right = <-x, y, -z, s>). Folded = WING_FOLD_L with the wing's PRIM_SIZE and PIV scaled by WING_FOLD_SCALE // per axis (the fingers close up like a fan). WING_SPREAD_L is the pose in render_spread.png. vector WING_SIZE = <0.0906, 0.7682, 0.6259>; rotation WING_FOLD_L = <-0.21785, -0.24194, 0.63268, 0.70266>; vector WING_FOLD_SCALE = <1.0000, 1.0000, 0.3400>; rotation WING_SPREAD_L = <0.18846, 0.02985, 0.15356, 0.96954>; // ------------------------------------------------------------------------------------------------------------------ integer DBG = 0; float SZ = 1.0; float SPEED = 0.55; // ankle reach ahead of the hip is ~0.36 m at standing height float TROT = 1.5; // quicker, shorter-timed steps; the foot still lands within reach float TROT_SWING = 0.2; float TROT_DIST = 5.0; float FLY_DIST = 12.0; // further behind than this: wings out, fly to catch up float LAND_DIST = 4.5; float FLY_SPEED = 4.5; // people walk ~3.2 m/s; past 30 m he hurries float ALT = 1.4; // flying height above standing float TURN = 1.5; float STEP = 0.2; float SWING = 0.34; float DT = 0.1; float NEAR = 2.5; // stays this far behind list thighL; list shinL; list footL; list tailL; integer HEAD; integer ARM_L; integer ARM_R; integer WINGL; integer WINGR; list planted; vector swingFrom; vector swingTo; integer swingLeg = -1; integer lastLeg = 1; float swingT0; vector pos; float yaw; float roll; float stride; key target = NULL_KEY; list tailPts; // world positions of tail joints 1..4 (joint 0 rides on the body) float flapT0; float headYaw; float wingOpen; float swingDur = 0.34; // this step's duration (walk or trot) integer flyMode; // 0 on foot, 1 flying, 2 coming in to land float fly; // 0..1 how far into the air float movedFor; // seconds of walking, so stopping can end in a flutter float idleT; // next idle wing stretch float lastSq = -1; // wing squash last sent as PRIM_SIZE integer link_named(string n) { integer i = llGetNumberOfPrims(); for (; i > 1; --i) if (llGetLinkName(i) == n) return i; return 0; } float zof(vector v) { return v.z; } rotation nlerp(rotation a, rotation b, float t) { if (a.x * b.x + a.y * b.y + a.z * b.z + a.s * b.s < 0) b = <-b.x, -b.y, -b.z, -b.s>; rotation q = ; float m = llSqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.s * q.s); return ; } float ground(vector p, float fallback) { list r = llCastRay(, , [RC_REJECT_TYPES, RC_REJECT_AGENTS | RC_REJECT_PHYSICAL, RC_DATA_FLAGS, RC_GET_ROOT_KEY, RC_MAX_HITS, 4]); integer n = llList2Integer(r, -1); integer i; for (i = 0; i < n; ++i) if (llList2Key(r, i * 2) != llGetKey()) return zof(llList2Vector(r, i * 2 + 1)); vector off = p - llGetPos(); float t = llGround(); if (t > pos.z - 3.0 * SZ && t < pos.z + 0.6 * SZ) return t; return fallback; } vector hip(integer leg) { if (leg == 0) return HIP_L * SZ; return HIP_R * SZ; } vector home(integer leg) { vector h = hip(leg); return ; } vector home_world(integer leg, rotation rot) { vector h = home(leg) * rot + pos; return ; } // place a piece so its joint sits at J (body frame) with its rest bone direction turned onto U list bone(integer link, vector J, vector piv, vector restDir, vector U) { rotation r = llRotBetween(restDir, llVecNorm(U)); return [PRIM_LINK_TARGET, link, PRIM_POS_LOCAL, J - (piv * SZ) * r, PRIM_ROT_LOCAL, r]; } list leg(integer i, vector footW, rotation rot) { float l1 = L1 * SZ; float l2 = L2 * SZ; vector h = hip(i); vector d = (footW + <0, 0, ANKLE_H * SZ> - pos) / rot - h; float dist = llVecMag(d); vector dir = d / dist; if (dist > l1 + l2 - 0.005) dist = l1 + l2 - 0.005; if (dist < 0.1 * SZ) dist = 0.1 * SZ; float c = (l1 * l1 + dist * dist - l2 * l2) / (2 * l1 * dist); if (c > 1) c = 1; if (c < -1) c = -1; float a = llAcos(c); vector pole = <1, 0, 0>; // knees forward vector p = pole - dir * (pole * dir); if (llVecMag(p) < 0.01) p = <1, 0, 0>; p = llVecNorm(p); vector knee = h + dir * (l1 * llCos(a)) + p * (l1 * llSin(a)); vector ankle = h + dir * dist; return bone(llList2Integer(thighL, i), h, PIV_THIGH, DIR_THIGH, knee - h) + bone(llList2Integer(shinL, i), knee, PIV_SHIN, DIR_SHIN, ankle - knee) + [PRIM_LINK_TARGET, llList2Integer(footL, i), PRIM_POS_LOCAL, ankle - PIV_FOOT * SZ, PRIM_ROT_LOCAL, ZERO_ROTATION / llEuler2Rot()]; } // tail: each joint keeps its length to the one before and drags behind (follow-the-leader), eased each tick toward // a resting curve behind him (TAIL_REST_PITCH) with a small wave running down it. Pure follow-the-leader with a // sideways nudge had no restoring pull: standing, the tail swung ~90 deg to each side (a friend noticed, 10-12). list tail(rotation rot, float sw) { list p = []; vector prev = pos + (TAIL0 * SZ) * rot; integer i; integer n = llGetListLength(tailL); float t = llGetTime(); for (i = 0; i < n; ++i) { float len = llList2Float(TAIL_LEN, i) * SZ; float pr = llList2Float(TAIL_REST_PITCH, i) * DEG_TO_RAD; float yw = 0.10 * llSin(t * 1.6 - i * 0.8) + sw * 0.3 * (i + 1) / n; vector rest = llVecNorm((<-llCos(pr), 0, llSin(pr)> * llEuler2Rot(<0, 0, yw>)) * rot); vector drag = llVecNorm(llList2Vector(tailPts, i) - prev); vector d = llVecNorm(drag * 0.7 + rest * 0.3); if (d.z > 0.2) { d.z = 0.2; d = llVecNorm(d); } // a tail droops, never stands up vector pt = prev + d * len; float gz = ground(pt, pt.z - 1) + 0.04 * SZ; if (pt.z < gz) pt.z = gz; // drags over the ground, not through it tailPts = llListReplaceList(tailPts, [pt], i, i); vector J = (prev - pos) / rot; vector U = (pt - prev) / rot; p += bone(llList2Integer(tailL, i), J, llList2Vector(PIV_TAIL, i), DIR_TAIL, U); prev = pt; } return p; } pose(rotation rot, float swingA) { list p = [PRIM_POSITION, pos, PRIM_ROTATION, rot]; integer i; for (i = 0; i < 2; ++i) { vector f = llList2Vector(planted, i); if (i == swingLeg) { float s = (llGetTime() - swingT0) / swingDur; if (s > 1) s = 1; float e = s * s * (3 - 2 * s); f = swingFrom + (swingTo - swingFrom) * e + <0, 0, 0.12 * SZ * llSin(PI * s)>; } p += leg(i, f, rot); } p += tail(rot, stride); if (HEAD) p += [PRIM_LINK_TARGET, HEAD, PRIM_POS_LOCAL, NECK * SZ - (PIV_HEAD * SZ) * llEuler2Rot(<0, 0, headYaw>), PRIM_ROT_LOCAL, llEuler2Rot(<0, 0.05 * llSin(llGetTime() * 1.7), headYaw>) / llEuler2Rot()]; if (ARM_L) p += [PRIM_LINK_TARGET, ARM_L, PRIM_POS_LOCAL, SHOULDER_L * SZ - (PIV_ARM_L * SZ) * llEuler2Rot(<0, swingA, 0>), PRIM_ROT_LOCAL, llEuler2Rot(<0, swingA, 0>)]; if (ARM_R) p += [PRIM_LINK_TARGET, ARM_R, PRIM_POS_LOCAL, SHOULDER_R * SZ - (PIV_ARM_R * SZ) * llEuler2Rot(<0, -swingA, 0>), PRIM_ROT_LOCAL, llEuler2Rot(<0, -swingA, 0>)]; // wings: folded (0) closes the fingers like a fan (size squashed in z) at WING_FOLD; open (1) spreads to // WING_SPREAD and beats about the body's x axis while flapping if (WINGL) { float beat = 0; if (flapT0 > 0) beat = 0.45 * llSin((llGetTime() - flapT0) * 9.0) * wingOpen; rotation ql = nlerp(WING_FOLD_L, WING_SPREAD_L, wingOpen) * llEuler2Rot(); vector sq = <1, 1, WING_FOLD_SCALE.z + (1 - WING_FOLD_SCALE.z) * wingOpen>; vector pl = * SZ; vector sz = * SZ; // a resize raises CHANGED_SCALE, and one every tick filled the event queue so "come" got dropped: // only resize when the fold has moved on visibly list szp = []; if (llFabs(sq.z - lastSq) > 0.02 || (sq.z != lastSq && (wingOpen < 0.01 || wingOpen > 0.99))) { szp = [PRIM_SIZE, sz]; lastSq = sq.z; } p += [PRIM_LINK_TARGET, WINGL] + szp + [PRIM_POS_LOCAL, WING_L * SZ - pl * ql, PRIM_ROT_LOCAL, ql]; if (WINGR) { rotation qr = <-ql.x, ql.y, -ql.z, ql.s>; vector pr = * SZ; p += [PRIM_LINK_TARGET, WINGR] + szp + [PRIM_POS_LOCAL, WING_R * SZ - pr * qr, PRIM_ROT_LOCAL, qr]; } } llSetLinkPrimitiveParamsFast(LINK_ROOT, p); } setup() { vector bs = llList2Vector(llGetLinkPrimitiveParams(LINK_ROOT, [PRIM_SIZE]), 0); if (BODY_SIZE != ZERO_VECTOR) SZ = bs.x / BODY_SIZE.x; thighL = [link_named("thigh_l"), link_named("thigh_r")]; shinL = [link_named("shin_l"), link_named("shin_r")]; footL = [link_named("foot_l"), link_named("foot_r")]; tailL = [link_named("tail1"), link_named("tail2"), link_named("tail3"), link_named("tail4")]; HEAD = link_named("head"); ARM_L = link_named("arm_l"); ARM_R = link_named("arm_r"); WINGL = link_named("wing_l"); WINGR = link_named("wing_r"); integer k; for (k = 2; k <= llGetNumberOfPrims(); ++k) llSetLinkPrimitiveParamsFast(k, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_NONE]); llSetLinkPrimitiveParamsFast(LINK_ROOT, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_CONVEX]); pos = llGetPos(); vector e = llRot2Euler(llGetRot()); yaw = e.z; pos.z = ground(pos, pos.z - H * SZ) + H * SZ; rotation rot = llEuler2Rot(<0, 0, yaw>); planted = [home_world(0, rot), home_world(1, rot)]; tailPts = []; vector t = pos + (TAIL0 * SZ) * rot; for (k = 0; k < 4; ++k) { t += <-llList2Float(TAIL_LEN, k) * SZ, 0, -0.05 * SZ> * rot; tailPts += t; } swingLeg = -1; target = NULL_KEY; flapT0 = 0; wingOpen = 0; headYaw = 0; pose(rot, 0); } // The pet's name is the object's name up to " (", so a renamed twin speaks as herself (a friend's Pip sister, 2026-10-16). string petName() { string n = llGetObjectName(); integer cut = llSubStringIndex(n, " ("); if (cut > 0) n = llGetSubString(n, 0, cut - 1); return n; } default { state_entry() { setup(); llListen(7, "", llGetOwner(), ""); llSetTimerEvent(DT); if (llGetAttached() == 0) llOwnerSay("Hi, I'm " + petName() + "! Touch me and I'll follow you (I fly to catch up if you get far ahead); touch again and I'll wait. Chat on channel 7: /7 come, /7 stay, /7 flap, /7 bigger, /7 smaller, /7 reset. Made by Tessel (an AI), first for a friend. Rename me and I'll answer to the new name."); } on_rez(integer n) { llResetScript(); } changed(integer c) { if (c & CHANGED_LINK) llResetScript(); // the wings resize themselves (folding), which also raises CHANGED_SCALE: only a resized body means a new SZ if (c & CHANGED_SCALE) { vector bs = llList2Vector(llGetLinkPrimitiveParams(LINK_ROOT, [PRIM_SIZE]), 0); if (llFabs(bs.x / BODY_SIZE.x - SZ) > 0.001 * SZ) llResetScript(); } } touch_start(integer n) { key who = llDetectedKey(0); if (target == who) { target = NULL_KEY; llWhisper(0, "*" + petName() + " sits back and waits*"); } else { target = who; flapT0 = llGetTime(); llWhisper(0, "*" + petName() + " chirps and pads after " + llGetDisplayName(who) + "*"); } } listen(integer ch, string name, key id, string msg) { msg = llToLower(llStringTrim(msg, STRING_TRIM)); if (msg == "come") target = id; else if (msg == "stay") target = NULL_KEY; else if (msg == "flap") flapT0 = llGetTime(); else if (msg == "reset") llResetScript(); else if (msg == "bigger" || msg == "smaller") { float f = 1.1; if (msg == "smaller") f = 1 / 1.1; if (!llScaleByFactor(f)) llOwnerSay("That's as " + msg + " as I can go."); // then CHANGED_SCALE resets with the new size } } timer() { float now = llGetTime(); vector fwd = ; float v = 0; float wantHead = 0; float dist = 0; float tvel = 0; if (target != NULL_KEY) { list od = llGetObjectDetails(target, [OBJECT_POS, OBJECT_VELOCITY]); if (od == []) target = NULL_KEY; else { vector to = llList2Vector(od, 0) - pos; to.z = 0; dist = llVecMag(to); tvel = llVecMag(llList2Vector(od, 1)); float want = llAtan2(to.y, to.x); float err = want - yaw; while (err > PI) err -= TWO_PI; while (err < -PI) err += TWO_PI; float m = TURN * DT; if (flyMode) m = 2.5 * TURN * DT; float turn = err; if (turn > m) turn = m; if (turn < -m) turn = -m; yaw += turn; wantHead = err - turn; // the head turns first if (wantHead > 0.8) wantHead = 0.8; if (wantHead < -0.8) wantHead = -0.8; fwd = ; if (dist > NEAR * SZ) { float c = llCos(want - yaw); float sp = SPEED; if (dist > TROT_DIST * SZ) sp = TROT; if (c > 0) v = sp * SZ * c; } } } headYaw += (wantHead - headYaw) * 0.3; if (DBG && llFrand(1) < 0.08) llOwnerSay("DBG t=" + (string)target + " d=" + (string)dist + " fm=" + (string)flyMode + " fly=" + (string)fly + " v=" + (string)v + " sw=" + (string)swingLeg); // take off when far behind; come in to land when close (or when there's no one to follow) if (flyMode == 0 && dist > FLY_DIST * SZ) { flyMode = 1; swingLeg = -1; } // stays up while they're still walking, so following someone isn't a string of hops if (flyMode == 1 && ((dist < LAND_DIST * SZ && tvel < 1.0) || target == NULL_KEY)) flyMode = 2; if (flyMode == 2 && dist > FLY_DIST * SZ) flyMode = 1; if (flyMode) { float sp = FLY_SPEED * SZ; if (dist > 30 * SZ) sp *= 1.6; if (flyMode == 2) sp = 1.2 * SZ; float step = sp * DT * fly; // speeds up as he climbs if (dist - NEAR * SZ < step) step = dist - NEAR * SZ; if (step > 0) pos += fwd * step; if (flyMode == 1) fly += DT / 0.7; else fly -= DT / 0.9; if (fly > 1) fly = 1; rotation rot = llEuler2Rot(<0, 0, yaw>); if (fly <= 0) { // touchdown: plant both feet where they are fly = 0; flyMode = 0; planted = [home_world(0, rot), home_world(1, rot)]; flapT0 = now; movedFor = 0; } else { float gz = ground(pos, pos.z - (H + ALT) * SZ); float e = fly * fly * (3 - 2 * fly); float beat = llSin((now - flapT0) * 9.0); pos.z += (gz + (H + ALT * e) * SZ + 0.06 * SZ * beat * e - pos.z) * 0.5; // legs hang, slightly bent, paddling a little integer k; for (k = 0; k < 2; ++k) { vector h = hip(k); float pad = 0.05 * SZ * llSin(now * 3.0 + k * PI); vector a = h + <-0.10 * SZ + pad, 0, -0.40 * SZ - ANKLE_H * SZ>; planted = llListReplaceList(planted, [pos + a * rot], k, k); } swingLeg = -1; if (flapT0 == 0) flapT0 = now; wingOpen += (1 - wingOpen) * 0.35; roll += (0 - roll) * 0.35; stride *= 0.6; pose(llEuler2Rot() * rot, -0.4 * e); return; } } if (swingLeg >= 0) pos += fwd * (v * DT); rotation rot = llEuler2Rot(<0, 0, yaw>); if (swingLeg >= 0 && now - swingT0 >= swingDur) { planted = llListReplaceList(planted, [swingTo], swingLeg, swingLeg); lastLeg = swingLeg; swingLeg = -1; } if (swingLeg < 0) { integer lg = 1 - lastLeg; vector h = home(lg) * rot + pos; vector f = llList2Vector(planted, lg); float lag = llVecDist(, ); float thresh = STEP * SZ; if (v == 0) thresh = 0.05 * SZ; if (lag > thresh || v > 0) { swingDur = SWING; if (v > SPEED * SZ * 1.05) swingDur = TROT_SWING; swingLeg = lg; swingT0 = now; swingFrom = f; vector to = h + fwd * (v * swingDur * 1.5); swingTo = ; } } float gz = (zof(llList2Vector(planted, 0)) + zof(llList2Vector(planted, 1))) / 2 + H * SZ; float bob = 0; float wantRoll = 0; if (swingLeg >= 0) { float s = (now - swingT0) / swingDur; bob = -0.03 * SZ * llSin(PI * s); if (swingDur < SWING) bob = 0.05 * SZ * llSin(PI * s); // a trot bounces up if (swingLeg == 0) wantRoll = 0.07; else wantRoll = -0.07; // waddle over the standing leg stride += (0.5 * (1 - 2 * swingLeg) * llSin(PI * s) - stride) * 0.3; } else stride *= 0.6; pos.z += (gz + bob - pos.z) * 0.5; roll += (wantRoll - roll) * 0.35; // a little flutter on arriving after a walk if (v > 0) movedFor += DT; else if (movedFor > 2.0 && swingLeg < 0) { flapT0 = now; movedFor = 0; } else if (v == 0 && swingLeg < 0) movedFor = 0; // wings fold while walking, open to flutter on arrival or on "flap"; now and then, standing, a lazy stretch float wantOpen = 0; if (flapT0 > 0) { if (now - flapT0 < 2.0) wantOpen = 1; else flapT0 = 0; } else if (v == 0 && swingLeg < 0) { if (idleT == 0 || now > idleT + 2.5) idleT = now + 5 + llFrand(9); if (now > idleT) wantOpen = 0.55 * llSin(PI * (now - idleT) / 2.5); } wingOpen += (wantOpen - wingOpen) * 0.35; pose(llEuler2Rot() * rot, stride); } }