Simply Maya User Community

Simply Maya User Community (https://simplymaya.com/forum/index.php)
-   Programming (https://simplymaya.com/forum/forumdisplay.php?f=32)
-   -   smart switch (https://simplymaya.com/forum/showthread.php?t=23587)

Velusion 24-10-2006 02:27 AM

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"?

AlphaFlyte 24-10-2006 04:26 PM

This sound like an evil workaround for the problem in my ears. I am no expert by far and by any means, but I think what you want is the possibility to switch between forward kinematics and inverse kinematics with an on / off switch or some such.

Now how to rig and set this up is a book's worth alone, and way beyond my own knowledge thus far.

Velusion 24-10-2006 05:03 PM

I'll try to post a short clip later on today to better explain what I'm doing. I don't think it's an IK/FK problem though. It has to do with being able to turn parenting (not parent constrain) on and off. I think the video I will post will explain it all.. stay tuned.

Xander-0 24-10-2006 07:11 PM

waaaay simpler method to do this;

after parenting the ikSolver to the control for it, you can parent that control to the controller for the whole body. This means that if you move the body, all the controllers with it (so when the creature jumps, the legs go too....). So how do you get it to bob around with its legs held steady on the ground (or anywhere)? Simple - create a locator. Then, point constrain (preferably, although I suppose occasionally a parent constraint can be used) the ikSolver's control handle to the locator (they don't even have to be in the same loaction either, although for obvious reasons doing this makes sense.). This will keep the feet in one posistion, allowing the body to move around without disturbing them. And it even has a built-in switch - when you want the thing to jump from that spot, simply set that point contraint's attribute to '0', and away you go.

That help?

Velusion 25-10-2006 02:26 AM

Sorry I didn't have time to prepare a video clip to show you guys but it looks like you understand my rigging/mel problem...

Xander-0,
Your idea seems promising. I haven't had time to test it but one thing that jumps to mind is the offset between the locator and the IK handle control once you point constrain them together. I agree that you can turn the constraint off but I think that once you turn it back on, the IK handle will snap back to the original offset position. I actually came up with a solution that was very close to the one you came up with but as I have already mentioned, once you turn the constraint back on, the IK control goes right back to the position of the point constraint plus the original offset. This is why I have been pursuing an expression that simply parents and unparents the IK handle to the body control. Again, my script works but the error message is just something I'd rather not have to look at. I'm still open to any and all ideas.


All times are GMT. The time now is 03:31 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018