# Not Quite Right Rotation

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

## Recommended Posts

So, I've read quite a bit but it seems like I am not quite getting how to work with rotations.  The script below basically creates a (useless) moving object.  Everything mostly works except the rotation isn't quite right.  Basically, when it runs, one cube, will "roll" around a second linked root prim cube in a sort of stepping motion.

It moves around fine, it even rotates in the expected direction, except it rolls 180 degrees every step, when it should only roll 90 degrees.  For example, I've textured it with a Dice Texture, and it only ever shows 6 or 1 on the top face.  I've tried replacing my rotation vector set with PI/2 and 1.58xx and removing the DEG_TO_RAD and using rotation instead of vectors.   I think the main issue lies somewhere in the conversions between vectors and rotations and degrees and radians.

```//Prim Positions
vector pos = <0.00000, -.5000, 0.0>;
rotation rot = <0.00000, 0.00000, 0.0, 1.0>;

list x_range = [  0, -.5, -.5, -.5,  0, .5, .5,  .5];
list y_range = [-.5, -.5,   0,  .5, .5, .5,  0, -.5];
list rot_range = [<0, -90, 0>,<0, -90, 0>,<-90, 0, 0>,<-90, 0, 0>,<0, 90, 0>,<0, 90, 0>,<90, 0, 0>,<90, 0, 0>];
integer position;

rotation NormRot(rotation Q)
{
float MagQ = llSqrt(Q.x*Q.x + Q.y*Q.y +Q.z*Q.z + Q.s*Q.s);
return <Q.x/MagQ, Q.y/MagQ, Q.z/MagQ, Q.s/MagQ>;
}

prim_mover()
{
float next_x=(float)llList2String(x_range,position);
float next_y=(float)llList2String(y_range,position);

pos = <next_x, next_y, pos.z>;
rotation next_rot = <rot_vector.x, rot_vector.y, rot_vector.z, 0.0>;
rot = rot * next_rot;
rot = NormRot(rot);

llSetPrimitiveParams([
PRIM_POS_LOCAL,pos,
PRIM_ROT_LOCAL,rot]);

if(position== 7)
{ position = 0;

}
else
{ position++;}
}

default
{
state_entry()
{
position = 0;
prim_mover();

llSetTimerEvent(1);
}

timer()
{
prim_mover();
}

}

```

##### Share on other sites

2 hours ago, Selphie Wirefly said:

rotation next_rot = <rot_vector.x, rot_vector.y, rot_vector.z, 0.0>;

• 2
##### Share on other sites

That fixed it, awesome.