shrtcww
02-04-2004, 02:39 AM
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];
}
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];
}
