Script: I want to connect child bone to tip of parent bone (not tail)

General Moho topics.

Moderators: Fahim, Distinct Sun, Víctor Paredes, erey, Belgarath, slowtiger

Post Reply
rinbox
Posts: 5
Joined: Sun Sep 29, 2019 6:59 am

Script: I want to connect child bone to tip of parent bone (not tail)

Post by rinbox » Wed Nov 20, 2019 12:54 pm

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?
User avatar
slowtiger
Posts: 5434
Joined: Thu Feb 16, 2006 6:53 pm
Location: Berlin, Germany
Contact:

Re: Script: I want to connect child bone to tip of parent bone (not tail)

Post by slowtiger » Wed Nov 20, 2019 2:07 pm

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.
AS 9.5 MacPro Quadcore 3GHz 16GB RAM OS 10.6.8 Quicktime 7.6.6
AS 11 MacPro 12core 3GHz 32GB RAM OS 10.11 Quicktime 10.7.3
rinbox
Posts: 5
Joined: Sun Sep 29, 2019 6:59 am

Re: Script: I want to connect child bone to tip of parent bone (not tail)

Post by rinbox » Wed Nov 20, 2019 2:41 pm

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.
User avatar
Lukas
Posts: 790
Joined: Fri Apr 09, 2010 9:00 am
Location: Netherlands
Contact:

Re: Script: I want to connect child bone to tip of parent bone (not tail)

Post by Lukas » Wed Nov 20, 2019 3:10 pm

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
rinbox
Posts: 5
Joined: Sun Sep 29, 2019 6:59 am

Re: Script: I want to connect child bone to tip of parent bone (not tail)

Post by rinbox » Thu Nov 21, 2019 12:16 pm

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.
Post Reply