Hey All,
Hopefully you can help me out with something I have been struggling with for a while. I am writing a wheel rotation script that you apply after the animation has been completed.
- It attaches a locator to the wheel that you have selected.
- By using magnitude, it calculates the distance the locator has traveled from the previous frame to the current frame and enters it into the distance array.
- Calculates the amount that the wheel should rotate based on the distance.
I have been trying to figure out how to tell when the locator / wheel changes direction more than 90 degrees (backwards) and change the $currDirection based on the direction.
Here's the code for the section in question:
// loop through locator vectors and populate magnitude distance array
for($i=$startFrame;$i< ($endFrame+1);$i++) {
int $offset = $i + 2;
int $currDirection = 1;
// In this section I need to figure out how to determine which direction the vector / locator is moving in, and change the $currDirection variable to positive or negative.
/*
if ($offset <= 101) {
$currDirection = 1;
} else {
$currDirection = -1;
}
*/
// calculate distance along vector
// Captures the translates for the previous postion of the wheel locator
vector $previousPos =getAttr -t ($i-1) ($myLocator+".translate")
;
// Captures the translates for the current postion of the wheel locator
vector $currentPos =getAttr -t $i ($myLocator+".translate")
;
//uses magnitude to calculate distance traveled by the wheel locator from the previous to current frame
$mag[$offset]= mag($currentPos - $previousPos);
//adds that value to the current distance, positive or negative value based on $currDirection
$distance[$offset]= $distance[$offset-1] + ($currDirection * $mag[$offset]);
}
Thank you very much for your help in advance.