Page 1 of 1
Script: I want to connect child bone to tip of parent bone (not tail)
Posted: Wed Nov 20, 2019 12:54 pm
by rinbox
I'm using Moho 13 Pro.
I can decide parent of bone by the following code.
local frame = 0
local skel = moho:Skeleton()
local child_bone = skel:AddBone(frame)
child_bone.fAnimParent:SetValue(frame, parent_bone_id)
In this case, however, the child bone is connected to the tail of the parent bone.
This behavior is also beneficial, but sometimes I want to connect child bone to tip of parent bone.
Is it possible?
Re: Script: I want to connect child bone to tip of parent bone (not tail)
Posted: Wed Nov 20, 2019 2:07 pm
by slowtiger
It doesn't matter wether you (manually) place your child bone at the top or bottom end of the parent bone - it just looks like that. The only position data Moho stores is the distance and angle to the parent bone's origin.
Re: Script: I want to connect child bone to tip of parent bone (not tail)
Posted: Wed Nov 20, 2019 2:41 pm
by rinbox
I see. What I should do is move the child bone to the tip of the parent bone.
I don't know how to find the coordinates of the tip of the parent bone, so I will try to find it.
Re: Script: I want to connect child bone to tip of parent bone (not tail)
Posted: Wed Nov 20, 2019 3:10 pm
by Lukas
This might get you started:
Code: Select all
local bone = skel:Bone(parent_bone_id)
local boneBase = LM.Vector2:new_local()
local boneTip = LM.Vector2:new_local()
boneBase:Set(0,0)
bone.fMovedMatrix:Transform(boneBase)
if not (bone:IsZeroLength()) then
boneTip:Set(bone.fLength, 0)
bone.fMovedMatrix:Transform(boneTip)
end
Re: Script: I want to connect child bone to tip of parent bone (not tail)
Posted: Thu Nov 21, 2019 12:16 pm
by rinbox
Thank you.
It worked fine the following code.
Code: Select all
local bone = skel:Bone(parent_bone_id)
local boneTip = LM.Vector2:new_local()
if not (bone:IsZeroLength()) then
boneTip:Set(bone.fLength, 0)
child_bone.fAnimPos:SetValue(frame, boneTip)
end
And I didn't use it this time, but I got a little deeper understanding of how to use matrix.