I have a 3-joint system with joints b1, b2, and b3 placed at 0.0, 0.5, and 1.0 along my object's Z axis, and they are free floating, not in a joint hierarchy. The object's origin is at the back end (in the same place as "b1.") Yes, they're all correctly oriented.
I am trying to make the object deform as it goes around a corner. For the first half of stepTime, only the b3 joint is turning. For the second half, both the b3 joint and the b2 joint are turning and b1 is still moving forward. This is the code I have so far:
function TurnLeft ()
{
var pivot : Vector3 = transform.TransformPoint(-1,0,1);
var pivotAxis : Vector3 = transform.TransformDirection(Vector3.up);
var halfStep : float = stepTime / 2;
var rotateRate : float = 90 * Time.deltaTime / halfStep;
nextTime = Time.time + halfStep;
while (Time.time < nextTime)
{
b1.localPosition = (Vector3.Lerp(Vector3(0,0,0),Vector3(0,0,0.5),(1-((nextTime - Time.time)/halfStep))));
b2.localPosition = (Vector3.Lerp(Vector3(0,0,0.5),Vector3(0,0,1),(1-((nextTime - Time.time)/halfStep))));
b3.RotateAround(pivot,pivotAxis,rotateRate);
yield;
}
nextTime = Time.time + halfStep;
while (Time.time < nextTime)
{
b1.localPosition = (Vector3.Lerp(Vector3(0,0,0.5),Vector3(0,0,1),(1-((nextTime - Time.time)/halfStep))));
b2.RotateAround(pivot,pivotAxis,rotateRate);
b3.RotateAround(pivot,pivotAxis,rotateRate);
yield;
}
JumpLeft();
}
This doesn't work. Of course. I hit the turn key and... what is this I don't even. It deforms, but it's FUBAR.
By comparison, this function works just fine:
function Proceed ()
{
nextTime = Time.time + stepTime
while (Time.time < nextTime)
{
myModel.localPosition = (Vector3.Lerp(Vector3(0,0,0),Vector3(0,0,1),(1-((nextTime - Time.time)/stepTime))));
yield;
}
JumpAhead();
}
// I know it will need a separate function to "unbend" in the following stepTime before it continues straight but I have to get the initial bend working before I worry about that.