# Rounded Turn for KeyFramed Motion

Please take a moment to consider if this thread is worth bumping.

## Recommended Posts

Function computes relative moves and rotations for a Key Framed Motion
Function takes arguments: in-going velocity, out-going velocity and radius of circle sector
The turning can be in any plane in space. Plane given by the two vectors
0° < turning < 180°

`// frames for turning motion, script by Dora Gustafson, Studio Dora 2014// function computes relative moves and rotations for a Key Framed Motion// function takes arguments: in-going velocity, out-going velocity and radius of circle sector// the turning can be in any plane in space. Plane given by the two vectors// 0° < turning < 180°// v1.01 tuned// v1.02 base rotation includedlist framesForTurn( vector Vin, vector Vout, float Radius ){    // Compute circle center and first position    float sinv = llSqrt(0.5*(1.0-llVecNorm(-Vin)*llVecNorm(Vout)));    vector Center = llVecNorm( llVecNorm(Vout)-llVecNorm(Vin))*Radius/sinv;    if ( Vin*Center > 0.0 ) Center = -Center;    vector startRadiusVector = llSqrt(Center*Center-Radius*Radius)*llVecNorm(-Vin)-Center;    // Compute time per step    float arch = PI-2.0*llAsin(sinv);    float steps = (float)llRound(arch/(10.0*DEG_TO_RAD));    float curvetime = arch*Radius/llVecMag(Vin);    float dT = curvetime/steps;    if ( dT < 0.11111111 ) dT = 0.11111111;    // initialize loop    list KFMlist = [];    vector axis = Vin%Vout;    rotation baserot = llGetRot();    vector U = Center+startRadiusVector;    rotation rotU = baserot;    vector V;    rotation rotV;    float step = 0.0;    while ( step < steps )    {        step += 1.0;        rotV = llAxisAngle2Rot( axis, arch*step/steps);        V = Center+startRadiusVector*rotV;        rotV = baserot*rotV;        KFMlist += [V-U, rotV/rotU, dT];        rotU = rotV;        U = V;    }    return KFMlist;}default{    touch_start( integer n)    {        llSetKeyframedMotion( [], []);        llSleep(0.2);        // 90° left turn in the X-Y plane, EXAMPLE        llSetKeyframedMotion( framesForTurn( <0.5, 0.0, 0.0>, <0.0, 0.5, 0.0>, 1.0), []);    }}`

The function needs a thorough testing and I would like to know if something needs fixing

:smileysurprised::):smileyvery-happy:

Edit: script updated with tuned version. Base rotation included

##### Share on other sites

I've only had a quick play with this, Dora, but it seems to work really well!

Thank you so much -- this is great stuff, and will be so useful.

##### Share on other sites

I've had another play with it, and I think, in practice, it's normally going to need the vectors translating by llGetRot(), thus:

`touch_start( integer n)    {        llSetKeyframedMotion( [], []);        llSleep(0.2);        // 90 degree left turn in the X-Y plane, EXAMPLE        rotation rot = llGetRot();        llSetKeyframedMotion( turn( <5.0, 0.0, 0.0>*rot, <0.0, 5.0, 0.0>*rot, 10.0), []);    }`

It's beautifully smooth.

##### Share on other sites

Nice catch
The raw vectors are global
With your addition they are made local which is most likely what is wanted with a vehicle on a track
The other option to have the vehicle stay on track is to rotate it before the motion