Page 1 of 1

Parent and un-parent an object from a character's hand

Posted: Sun Aug 20, 2017 7:45 am
by Rnoir
There might be a simple solution to this, but I couldn't find and andswer to it yet.
I want to make characters grab objects from the background or from other characters hands. So basically I want to know how to parent that object to a character's hand at the moment the character grabs it and un-parent the object when the character drops said object or gives it to another character (meaning un-parent the object from the character's hand giving it and parenting the object to the character receiving it).

Image

Re: Parent and un-parent an object from a character's hand

Posted: Sun Aug 20, 2017 8:29 am
by slowtiger
The simple solution: duplicate the object, place one on the table, include the other one into the character rig (bind it to the hand) and make it invisible. Switch visibility when needed.

Re: Parent and un-parent an object from a character's hand

Posted: Sun Aug 20, 2017 1:09 pm
by Víctor Paredes
You can also animate the bone parenting. To do that, the object must be inside of the bone layer and be bound to its own non parented bone.
At the frame the character hand is close to the object, select the object's bone and then the Reparent bone tool and click over the hand bone. Now the object bone will be child of the hand.

Re: Parent and un-parent an object from a character's hand

Posted: Sun Aug 20, 2017 6:16 pm
by Greenlaw
I was going to mention keyframing bone parenting but Victor beat me to it.

That said, if I was doing this, I would follow SlowTiger's suggestion. Swapping the visibility between duplicate objects is easier to set up and manage, and is less likely to mess up if you need to change your rig or animation later. (IMHO.)

But certainly try both so you can see the difference, and choose the method that works best for you.

A note to Moho developers who maybe reading this: I might feel differently if bone parent keys could use other interpolation modes and not just step mode, like key-frameable constraints found in many 3D animation programs. (Same with Bone targeting; maybe more so with targets.) :)

Re: Parent and un-parent an object from a character's hand

Posted: Sun Aug 20, 2017 10:27 pm
by Rnoir
slowtiger wrote:The simple solution: duplicate the object, place one on the table, include the other one into the character rig (bind it to the hand) and make it invisible. Switch visibility when needed.
Víctor Paredes wrote:You can also animate the bone parenting. To do that, the object must be inside of the bone layer and be bound to its own non parented bone.
At the frame the character hand is close to the object, select the object's bone and then the Reparent bone tool and click over the hand bone. Now the object bone will be child of the hand.
Ok, both methods seems to work. Thanks for the tips!

Re: Parent and un-parent an object from a character's hand

Posted: Mon Aug 21, 2017 11:08 am
by hayasidist
Greenlaw wrote:A note to Moho developers who maybe reading this: I might feel differently if bone parent keys could use other interpolation modes and not just step mode, like key-frameable constraints found in many 3D animation programs. (Same with Bone targeting; maybe more so with targets.) :)
hear hear!! and wouldn't it be nice if a bone could have a target in a different group...

Re: Parent and un-parent an object from a character's hand

Posted: Mon Aug 21, 2017 12:14 pm
by slowtiger
I wonder if that's possible at all, since I believe Moho still calculates and renders one layer after another (thus its mask construction) and "forgets" it after that. Targetting something in a different layer hierarchy would need some temporal memory for something which might have been rendered or will be rendered at a different point in time.

Re: Parent and un-parent an object from a character's hand

Posted: Mon Aug 21, 2017 3:47 pm
by Greenlaw
hayasidist wrote:hear hear!! and wouldn't it be nice if a bone could have a target in a different group...
I would love that. I often wish we had a 'global' bone layer at the top, where I can add bones that any sub-level bones could be targeted or parented to.

For example, when I need to animate two characters holding hands. Currently, I must either put all the character art and bones under the same bone group, or carefully matchmove the independent arms rigs frame by frame, or make a target bone for each rig and then copy/paste the keys from one target to the other whenever I change the animation. (The latter is my preferred method but it's still a little clunky.)

It would be much easier if I could add a shared 'hand' target bone in a master bone layer, and then target both characters' forearm bones to it from their individual bone layers.

Re: Parent and un-parent an object from a character's hand

Posted: Mon Aug 21, 2017 5:27 pm
by hayasidist
slowtiger wrote:I wonder if that's possible at all ...
it's straightforward with a layer script and hard coded bone names:

Code: Select all

function LayerScript(moho)
	local vec = LM.Vector2:new_local()
	if moho.frame == 0 then
		return true
	end
	local doc = moho.document
	local control = doc:LayerByName("control")
	control = moho:LayerAsBone(control)
	local controlSkel = control:Skeleton()
	local controlBone = controlSkel:BoneByName("bone")
	local skel = moho:Skeleton()
	if not skel then
		return false
	end
	local vec = LM.Vector2:new_local()
	vec:Set(controlBone.fPos)
	local controlledBone = skel:BoneByName("target") 
	local id = skel:BoneID(controlledBone)
	skel:IKAngleSolver(id, vec)
end
try it with a moho doc that has:

bone layer 1: has a bone in it called "target" (at the end of a bone chain) and it's this layer that gets the embedded script.
bone layer 2: is called "control" and has a bone in it called "bone" -- to keep things simple (re calculating position) for this script I've assumed "bone" is un-parented - this bone dances around ...
.. and the "target" follows it.

(and, yes, I could have cut down the number of lines of code by cutting out unnecessary intermediate local variables but this was a proof of concept thrown together in 30 mins or so)