CGTalk > Software > Autodesk Maya > Maya Programming
Login register
Thread Closed share thread « Previous Thread | Next Thread »  
 
Thread Tools Search this Thread Display Modes
Old 02-04-2004, 03:39 AM   #1
shrtcww
New Member
 
shrtcww's Avatar
portfolio
Ian Jones
Character TD
LucasArts
San Francisco, USA
 
Join Date: Feb 2004
Posts: 27
Send a message via AIM to shrtcww Send a message via MSN to shrtcww
Trying to have an object 'track' down another

Premise: Have one object (CTRL_Car) which will 'drive' the second object Car.

Problem: Script doesnt seem to fully execute/run on each transform of CTRL_Car. Any Ideas?

Currently I'm trying to:
1) Set Inital variables for each objects local positions
2) On a move of the CTRL update the second set of variables and calculate the distance ($distance) between them.
3) Rotate the Car towards the CTRL_Car (done currently always with an AIM contraint, later will modify its weight to make more realistic)
4)Move the car $distance towards the CTRL
5)Reset the orignal x/z positions for the next time

Current Code:

//Del values of Car and its Controller
float $carctrl[] = `xform -q -os Car`;
float $CTRL_pos[] = `xform -q -os CTRL_Car`;
$carctrl[0] = 0;
$CTRL_pos[0] = 0;
$carctrl[2] = 0;
$CTRL_pos[2] = 0;

float $distance = 0;

//Distance Between Car and Car Controller
float $test = 0;

//Update Car Controller's position with latest translation.
$CTRL_pos[2] = CTRL_Car.translateX;
$CTRL_pos[2] = CTRL_Car.translateZ;

//Calculate Distance
float $deltaX = $CTRL_pos[0] - $carctrl[0];
float $deltaZ = $CTRL_pos[2] - $carctrl[2];
float $tempX = `pow $deltaX 2`;
float $tempZ = `pow $deltaZ 2`;
$distance = sqrt($tempX + $tempZ);
move -r 0 0 $distance Car;

//Reset Distance moved
if ($distance != 0)
{
$carctrl[0] = $CTRL_pos[0];
$carctrl[2] = $CTRL_pos[2];
}
 
Old 02-05-2004, 12:52 AM   #2
mark_wilkins
Scream.
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 1,339
Because Maya doesn't see the xform -q or move commands as equivalent to a connection, it doesn't know when it has to execute the expression.

This is a big problem with using MEL commands in the middle of expressions. You can set the expression's "always evaluate" toggle on, which may help (though there are certain circumstances under which even this won't solve the problem completely.)

An alternative is to query the control object's translateX and translateZ by assigning them to a local variable (rather than using the xform command), and assign new position values directly to tx and tz rather than using the move command. This will make your updating work out better.

Here's my version of your expression:
Code:
float $distance = 0.1; vector $ctrl_direction = <<locator1.translateX - tx, 0, locator1.translateZ - tz>>; vector $norm_ctrl_direction = $ctrl_direction / mag($ctrl_direction); vector $move_vec = $norm_ctrl_direction * $distance; tx += $move_vec.x; tz += $move_vec.z;


"But," you say, "the expression has to have the node name of the control object available in it!" Yes, it does. The solution to this is to build a small MEL script that you use for setting up the car/control relationship. This MEL script will look at the name of the control object you've selected and use the expression command to make the above expression.

Another alternative which I *MUCH* prefer if you're going to have a lot of these things, because it will be much, much faster and much simpler to set up, is to use particle dynamics. You can set up a particle object whose particles follow per-particle goals around just as you've done with your expression, then use geometry instancing to put a car at each particle. Not only will this be faster, but it will also save memory if you have multiple of the same car in the scene.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
 
Old 01-17-2006, 09:00 AM   #3
CGTalk Moderation
Lord of the posts
CGTalk Forum Leader
 
Join Date: Sep 2003
Posts: 1,066,480
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 01:44 AM.


Powered by vBulletin
Copyright ©2000 - 2016, Jelsoft Enterprises Ltd.