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

General Moho topics.

Moderators: Víctor Paredes, 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 »

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: 6067
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 »

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 OS 10.6.8 Quicktime 7.6.6
AS 11 MacPro 12core 3GHz 32GB OS 10.11 Quicktime 10.7.3
Moho 13.5 iMac Quadcore 2,9GHz 16GB OS 10.15

Moho 14.1 Mac Mini Plus OS 13.5
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 »

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: 1294
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 »

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 »

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