x


Trying to incrementally RotateAround on joints; becoming enraged

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.
more ▼

asked May 03 '11 at 11:35 AM

terablargh gravatar image

terablargh
74 6 7 15

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Don't even use rotateAround, make an empty "pivot" GameObject, rotate that, and parent and unparent the joints to it as needed. Duh!

(I wasn't aware originally that you could change an objects' parent with a script.)

more ▼

answered May 13 '11 at 03:09 PM

terablargh gravatar image

terablargh
74 6 7 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x146
x87

asked: May 03 '11 at 11:35 AM

Seen: 459 times

Last Updated: May 03 '11 at 11:35 AM