View Full Version : Offsetting Actions using MEL

 Randolph10 October 2005, 01:28 PMLet's say I want Car 2 to follow Car 1 in a certain distance. Using this expression Car2.translateX = `getAttr -time (frame - 5) Car1.translateX`; is doing well as long as Car 1 is running. If it stops Car 2 will crash into his rear of course. What I want is that Car 2 stays allways in this certain distance to Car 1, even if Car 1 turns left or right or stops. In other words and to make it more geneal: Car 2 shall reproduce the transformations of Car 2 with a time offset, but keep the distance if Car 1 stops (and goes on after a few frames of resting). There is a work around using a motion path (and expressions), but I need a solution without this, because I've got a lot of cars, and I want the whole thing get running via MEL. Could anybody tell me how? Thanks in advance
drGonzo
10 October 2005, 05:15 PM
Why not calculate the distance in between both cars (or locators) using the mag command and writing a conditional based on that result?
This snippet calculates the distance between 2 particles, but it could get you started:

global proc string getParticleDistance()
{
float \$part1Pos[] = `getParticleAttr -at position particle1.pt[0]`;
float \$part2Pos[] = `getParticleAttr -at position particle1.pt[1]`;
float \$distancePos[];
\$distancePos[0] = \$part1Pos[0] - \$part2Pos[0];
\$distancePos[1] = \$part1Pos[1] - \$part2Pos[1];
\$distancePos[2] = \$part1Pos[2] - \$part2Pos[2];
float \$distance = `mag <<\$distancePos[0], \$distancePos[1], \$distancePos[2]>>`;
return \$distance;
}

CGTalk Moderation
10 October 2005, 05:15 PM
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.

1