Basic Info: This script allows you to control bones within child bone or switch layers. In other words, if you have a situation that looks like this:
Bone Layer A:
---Bone Layer B: (Has a bone called "hands")
--------Vector Layer (Named Hands)
You can control the bone "hands" in Bone Layer B from Bone Layer A. Just embed my script in Bone Layer B and then create a new bone in Bone Layer A and name it the same as the bone you want to control in the lower bone layer. If you're confused, here's an example:
Bone Layer A: (Now has a new bone called "hands")
--Bone Layer B: (Has a bone called "hands" and this layer has the control script attached to it)
---------Vector Layer (Named Hands)
This script works for smartbones and it's independent of grid location so you can put bones where ever the heck you want!
This script comes in 2 flavors! The first is Global and the other is Switch Sensitive.
The global version of the script controls everything you assign beneath it. This will work for most occasions, but it might get a little troublesome if you have a switch layer with a bunch of bones. This script could crash your program if you try to control something like 20 smart bones in a switch layer all at the same time, so I created a switch sensitive version as well.
The Switch Sensitive version of this script only moves the bones in a switch layer that is currently active, essentially ignoring all the inactive bones.
DOWNLOAD LINK: https://docs.google.com/file/d/0Bwzk-fA ... sp=sharing
GLOBAL VERSION:
Code: Select all
-- #####################################################
-- NESTED BONE CONTROL - Layer Script
-- v1.0
-- Created by Derek Root
-- DKWROOT @ Lost Marble Forums
-- #####################################################
function LayerScript(moho)
local skel = moho:Skeleton()
local parent_skeleton=moho:ParentSkeleton()
local frame = moho.frame
if (skel == nil) then
return
end
if (parent_skeleton == nil) then
return
end
for i=0, skel:CountBones()-1 do
local child_bone=skel:Bone(i)
for j=0, parent_skeleton:CountBones()-1 do
local parent_bone=parent_skeleton:Bone(j)
if (child_bone:Name() == parent_bone:Name()) then
child_bone.fStrength = parent_bone.fStrength
child_bone.fLength = parent_bone.fLength
child_bone.fOffset = parent_bone.fOffset
child_bone.fAngle = parent_bone.fAngle
child_bone.fScale = parent_bone.fScale
if (frame>0) then
local origin = LM.Vector2:new_local()
local bonemoved = LM.Vector2:new_local()
local origin2 = LM.Vector2:new_local()
origin:Set(0,0)
parent_bone.fRestMatrix:Transform(origin)
bonemoved:Set(0,0)
parent_bone.fMovedMatrix:Transform(bonemoved)
local dxy = origin - bonemoved
if (child_bone.fParent < 0 ) then
origin2:Set(0,0)
child_bone.fRestMatrix:Transform(origin2)
child_bone.fPos.x = origin2.x - dxy.x
child_bone.fPos.y = origin2.y - dxy.y
else
--THIS PART WOULD ALLOW CONTROL BONES TO MOVE NESTED BONES THAT ARE LINKED
--UNFORTUNATELY, I HAVE YET TO MAKE IT WORK.
end
end
end
end
skel:UpdateBoneMatrix()
end
end
SWITCH SENSITIVE VERSION:
Code: Select all
-- #####################################################
-- NESTED BONE CONTROL - Layer Script
-- v1.0
-- Created by Derek Root
-- DKWROOT @ Lost Marble Forums
-- #####################################################
function LayerScript(moho)
local skel = moho:Skeleton()
local parent_skeleton=moho:ParentSkeleton()
local frame = moho.frame
if (skel == nil) then
return
end
if (parent_skeleton == nil) then
return
end
local parLayer = moho.layer:Parent()
local TEST = 0
if (parLayer:LayerType() == 5) then
local switchname = parLayer:SwitchValues():GetValue(frame)
if (moho.layer:Name() == switchname) then
TEST = 1
else
TEST = 0
end
else
TEST = 1
end
if (TEST == 1) then
for i=0, skel:CountBones()-1 do
local child_bone=skel:Bone(i)
for j=0, parent_skeleton:CountBones()-1 do
local parent_bone=parent_skeleton:Bone(j)
if (child_bone:Name() == parent_bone:Name()) then
child_bone.fAngle = parent_bone.fAngle
child_bone.fScale = parent_bone.fScale
child_bone.fStrength = parent_bone.fStrength
child_bone.fLength = parent_bone.fLength
child_bone.fOffset = parent_bone.fOffset
if (frame>0) then
local origin = LM.Vector2:new_local()
local bonemoved = LM.Vector2:new_local()
local origin2 = LM.Vector2:new_local()
origin:Set(0,0)
parent_bone.fRestMatrix:Transform(origin)
bonemoved:Set(0,0)
parent_bone.fMovedMatrix:Transform(bonemoved)
local dxy = origin - bonemoved
if (child_bone.fParent < 0 ) then
origin2:Set(0,0)
child_bone.fRestMatrix:Transform(origin2)
child_bone.fPos.x = origin2.x - dxy.x
child_bone.fPos.y = origin2.y - dxy.y
end
end
end
end
skel:UpdateBoneMatrix()
end
end
end