Thread: smart switch
View Single Post
# 1 24-10-2006 , 02:27 AM
Velusion's Avatar
Registered User
Join Date: May 2004
Location: Utah, USA
Posts: 369

smart switch

I have a creature model that is basically just a body and 2 arms. The arms use an IK solver. The model is rigged so that I can move the body without moving the arms. This way, the arms can be posed so that when the body is bobbing and rotating, the arms appear to be supporting the body. Like a legless man using his arms to hold himself up.

There are going to be times when I want the arms to move with the body. For instance, times when the creature uses its arms to throw itself into the air. At those times I want the arms to move with the body but still be animatable. In other words, I want the arms to be parented to the controller that I use to move the body but also able to move relative to its following of the body. I decided that I can't just set up a point constraint between the body controller and the IK controllers on the creature's wrists because.

If I parent the IK controllers on the creature's wrists to the body controller then the arms will move with the body and I will also be able to move the arms relative to the body (have them swing around while the creature moves through the air). The problem is that you can't turn off the parenting of the arm IK controls to the body so that I can also have the body move without moving the arms. (NOTE: Parenting, not Parent constraint)

My solution was to make an attribute on the body controller that could be keyed from 0 (off) to 1 (on) and then write an expression that would either parent or unparent the arm IK controls from the body controller based on the state on the attribute.


The creature body controller is called Monster_handle
The custom attribute is called IK_mag

Here is the script I wrote:

float $mag= `getAttr Monster_handle.IK_mag`;

if ($mag==0)
{
select -r Lft_wrist_ctr ;
parent -w;
select -cl;
select -r Rg_wrist_ctr ;
parent -w;
}
if ($mag==1)
{
select -r Lft_wrist_ctr;
select -tgl Monster_handle;
parent;
select -cl;
select -r Rg_wrist_ctr;
select -tgl Monster_handle;
parent;
}


The script works well enough but during animation it generates error messages since the state of the IK_mag attribute is being evaluated at everyframe which causes the expression to try to parent the control objects every frame (if IK_mag==1) or unparent them every frame (if IK_mag==0). In other words, the expression is trying to parent something that is already parented or unparent something that is already unparented.

My problem is that I don't know enough MEL to write a routine that will not execute the parenting/unparenting commands if the IK_mag attribute hasn't changed from the previous frame.

Can anyone help me? Is there a way to write a routine that basically states "if nothing has changed then skip to the next frame"?


Last edited by Velusion; 24-10-2006 at 02:32 AM.