Hi "mohonians",
I hope you can help me with this.
Let's say we have two bones: A and B.
I need bone A to rotate randomly (and automatically put a keyframe on rotations) every time that a keyframe is put on whatever channel of bone B (it could be rotations, positions, switch channel etc).
I hope it's clear enough.
Thanks in advance for your mind squeezing.
Matteo
Bone A randomly driven by bone B
Moderators: Víctor Paredes, Belgarath, slowtiger
- keepfungus
- Posts: 62
- Joined: Fri Jun 10, 2011 10:15 am
- Location: Rome, Italy
- Contact:
Bone A randomly driven by bone B
vimeo.com/matteoloi
instagram.com/keepfungus/
justeleven.it
twitter.com/justeleven
instagram.com/keepfungus/
justeleven.it
twitter.com/justeleven
- hayasidist
- Posts: 3841
- Joined: Wed Feb 16, 2011 8:12 pm
- Location: Kent, England
Re: Bone A randomly driven by bone B
layerscript.
for example: (this uses fixed bone names; only looks for angle and position and doesn't really try to randomise Bone "A")
It will benefit from enhancement e.g. to have bones selectable and to add all the channels and proper randomisation but I hope you get the idea ...
for example: (this uses fixed bone names; only looks for angle and position and doesn't really try to randomise Bone "A")
It will benefit from enhancement e.g. to have bones selectable and to add all the channels and proper randomisation but I hope you get the idea ...
Code: Select all
function LayerScript(moho)
-- v0.0
if moho.frame == 0 then
return
end
local skel = moho:Skeleton()
if not skel then
return false
end
local checkBoneName = "B1"
local checkBone = skel:BoneByName(checkBoneName)
if not checkBone then
return false
end
local controlledBoneName = "B2"
local controlledBone = skel:BoneByName(controlledBoneName)
if not controlledBone then
return false
end
local channels = {checkBone.fAnimAngle, checkBone.fAnimPos}
for i = 1, #channels do
if channels[i]:HasKey(moho.frame) then
if not controlledBone.fAnimAngle:HasKey(moho.frame) then
controlledBone.fAnimAngle:SetValue(moho.frame, math.rad(moho.frame/10))
end
break
end
end
end
- Víctor Paredes
- Site Admin
- Posts: 5814
- Joined: Wed Jan 26, 2005 12:18 am
- Location: Barcelona/Chile
- Contact:
Re: Bone A randomly driven by bone B
I have a setup that could create something similar to what you are looking for (if I understood the idea).
Please check this file.
I have these 4 Bones:

Here's how it's setup:
Bone B's angle is controlled by Bone C by a very high number (3477, but it can be any big value, really).
This makes that every time you rotate Bone C, Bone B will also rotate, but a lot more. So Bone B will end at a random angle.
Then, I created Bone A and, child of it, the bone named Target.
So if you scale, rotate or translate Bone A, then Target will also move with it.
Finally, I set Target as the target for Bone C.
So Bone C will always rotate to point to the Target bone.
At the end, you rotate/scale/translate Bone A. That changes the position of the bone Target. That changes the angle of Bone C and that change of angle is multiplied on Bone B.
I hope it helps (and makes sense!)
PS: I just saw the script there. Yes, probably that's better than what I wrote here
Please check this file.
I have these 4 Bones:

Here's how it's setup:
Bone B's angle is controlled by Bone C by a very high number (3477, but it can be any big value, really).
This makes that every time you rotate Bone C, Bone B will also rotate, but a lot more. So Bone B will end at a random angle.
Then, I created Bone A and, child of it, the bone named Target.
So if you scale, rotate or translate Bone A, then Target will also move with it.
Finally, I set Target as the target for Bone C.
So Bone C will always rotate to point to the Target bone.
At the end, you rotate/scale/translate Bone A. That changes the position of the bone Target. That changes the angle of Bone C and that change of angle is multiplied on Bone B.
I hope it helps (and makes sense!)
PS: I just saw the script there. Yes, probably that's better than what I wrote here







Moho co-owner
Previously Rigged animation supervisor: My father's dragon, Wolfwalkers & Star Wars Visions "Screecher's Reach"
My personal Youtube Channel
- keepfungus
- Posts: 62
- Joined: Fri Jun 10, 2011 10:15 am
- Location: Rome, Italy
- Contact:
Re: Bone A randomly driven by bone B
Thanks a lot! I'll definitely try it.hayasidist wrote: ↑Thu May 11, 2023 3:13 pm layerscript.
for example: (this uses fixed bone names; only looks for angle and position and doesn't really try to randomise Bone "A")
It will benefit from enhancement e.g. to have bones selectable and to add all the channels and proper randomisation but I hope you get the idea ...Code: Select all
function LayerScript(moho) -- v0.0 if moho.frame == 0 then return end local skel = moho:Skeleton() if not skel then return false end local checkBoneName = "B1" local checkBone = skel:BoneByName(checkBoneName) if not checkBone then return false end local controlledBoneName = "B2" local controlledBone = skel:BoneByName(controlledBoneName) if not controlledBone then return false end local channels = {checkBone.fAnimAngle, checkBone.fAnimPos} for i = 1, #channels do if channels[i]:HasKey(moho.frame) then if not controlledBone.fAnimAngle:HasKey(moho.frame) then controlledBone.fAnimAngle:SetValue(moho.frame, math.rad(moho.frame/10)) end break end end end
vimeo.com/matteoloi
instagram.com/keepfungus/
justeleven.it
twitter.com/justeleven
instagram.com/keepfungus/
justeleven.it
twitter.com/justeleven
- keepfungus
- Posts: 62
- Joined: Fri Jun 10, 2011 10:15 am
- Location: Rome, Italy
- Contact:
Re: Bone A randomly driven by bone B
Victor, I can only say...GENIAL!
It works just fine.
Since the "final" bone needed to rotate between two limits (0°-180°) I added a final bone (the green one in the video) with limits which follows a target bone parented to the "random" bone.
Your lateral thinking is always inspiring.
Thanks so much!
It works just fine.
Since the "final" bone needed to rotate between two limits (0°-180°) I added a final bone (the green one in the video) with limits which follows a target bone parented to the "random" bone.
Your lateral thinking is always inspiring.
Thanks so much!
vimeo.com/matteoloi
instagram.com/keepfungus/
justeleven.it
twitter.com/justeleven
instagram.com/keepfungus/
justeleven.it
twitter.com/justeleven
- Víctor Paredes
- Site Admin
- Posts: 5814
- Joined: Wed Jan 26, 2005 12:18 am
- Location: Barcelona/Chile
- Contact:
Re: Bone A randomly driven by bone B
Nice! I'm happy this idea was helpful for you 







Moho co-owner
Previously Rigged animation supervisor: My father's dragon, Wolfwalkers & Star Wars Visions "Screecher's Reach"
My personal Youtube Channel