// Wheel spinner: drop into the ROOT of a vehicle. Every linked prim whose name contains "wheel" spins at the // speed the vehicle rolls (forward or back), and stops when it stops. Spin is client-side (PRIM_OMEGA): smooth, // no lag. If a wheel spins the wrong way or around the wrong axis, change AXLE (the wheel's own local axis // through its hub; a cylinder turned on its side usually spins around its local Z = <0,0,1>). // Made by Tessel (an AI) for a friend, 2026-10-12. Free to use, copy and change. vector AXLE = <0, 0, 1>; float SIGN = 1.0; // set to -1.0 if they roll backwards list wheels; list radii; list lrots; float lastRate = -999; vector lastPos; float lastT; find() { wheels = []; radii = []; lrots = []; llSetLinkPrimitiveParamsFast(LINK_ROOT, [PRIM_OMEGA, <0, 0, 1>, 0.0, 0.0]); // clear any spin an older version left on the root integer n = llGetNumberOfPrims(); integer i; for (i = 2; i <= n; ++i) // never the root: spinning a physical root turns the whole vehicle (my renamed "...spinning wheels" cart drove in circles) if (llSubStringIndex(llToLower(llGetLinkName(i)), "wheel") != -1) { vector s = llList2Vector(llGetLinkPrimitiveParams(i, [PRIM_SIZE]), 0); float r = s.x; if (s.y > r) r = s.y; if (s.z > r) r = s.z; // biggest dimension = diameter wheels += i; radii += r / 2; lrots += llList2Rot(llGetLinkPrimitiveParams(i, [PRIM_ROT_LOCAL]), 0); // purely visual: wheels that collide drag a physical vehicle into circles (a friend's cart, 2026-10-12) llSetLinkPrimitiveParamsFast(i, [PRIM_PHYSICS_SHAPE_TYPE, PRIM_PHYSICS_SHAPE_NONE]); } llOwnerSay("Wheel spinner: found " + (string)llGetListLength(wheels) + " wheel(s)."); } default { state_entry() { find(); llSetTimerEvent(0.25); } changed(integer c) { if (c & CHANGED_LINK) find(); } on_rez(integer p) { llResetScript(); } timer() { // each wheel rolls along (its axle x up): works whichever way the vehicle's mesh faces // velocity from position change: llGetVel is zero for vehicles moved non-physically (a friend's cart is) vector pos = llGetRootPosition(); float now = llGetTime(); vector v = ZERO_VECTOR; if (lastT > 0 && now > lastT) v = (pos - lastPos) / (now - lastT); lastPos = pos; lastT = now; v.z = 0; rotation rr = llGetRootRotation(); if (llVecMag(v) < 0.05) v = ZERO_VECTOR; float spd = llVecMag(v); if (llFabs(spd - lastRate) < 0.1 && !(spd == 0 && lastRate != 0)) return; lastRate = spd; list p; integer i; for (i = 0; i < llGetListLength(wheels); ++i) { vector axleW = AXLE * (llList2Rot(lrots, i) * rr); vector roll = llVecNorm(axleW % <0, 0, 1>); float spin = SIGN * (v * roll) / llList2Float(radii, i); // PRIM_OMEGA's axis on a child is in the root's frame, not the wheel's: without this the wheels flipped like coins p += [PRIM_LINK_TARGET, llList2Integer(wheels, i), PRIM_OMEGA, AXLE * llList2Rot(lrots, i), spin, 1.0]; } llSetLinkPrimitiveParamsFast(LINK_ROOT, p); } }