# Rotating Child Prims

## Recommended Posts

I'm have a cylinder that is cut into five pieces I want to rotate those pieces as if there was a stick going the center. I'm using this

```float y = 90;
float yh = 90;
integer yt = 90;
integer yth = 90;
integer  One = FALSE;
integer  Two = FALSE;
integer  Three = FALSE;
integer x;
integer t;
integer th;
float   gap = 30.0;
rotation rot_xyzs;

default
{
state_entry()
{
}

touch_start(integer total_number)
{
{

//First

vector xyz_angles = <y,1.0,1.0>; // This defines a 1 degree change on the Y axis

y+=90;
// x++;

}
}
}```

but it seems that the first click it is setting itself to a start point before rotating. Any ideas?

##### Share on other sites

Sorry it's a bit of a mess and there are unused variables in there. I've been trying a few different ways with the same effect.

##### Share on other sites

I am not at all sure what you're trying to do there.

However, what you are telling it to do, is to set itself to an angle of 90 degrees on on the positive z axis.

If you want to tell it to rotate through  90 degrees from whatever angle it's at when you touch it, then try

```rotation r = llList2Rot(llGetLinkPrimitiveParams(5,[PRIM_ROT_LOCAL]),0);

(I think that should work -- not tested though).

##### Share on other sites

I have this script which I put into the child prim. It rotates it fine. When I try to use llSetLinkPrimitiveParamsFast in the root prim though, rotates weird. It's like reorienting itself to the axis before it starts the rotations.

```rotation rot_xyzq;

default
{
state_entry()
{
vector xyz_angles = <0,0.90,0>; // This is to define a 90 degree change
rot_xyzq = llEuler2Rot(angles_in_radians); // Change to a Rotation
}

touch_start(integer s)
{
llSetRot(llGetRot()*rot_xyzq/llGetRootRotation()/llGetRootRotation()); //Do the Rotation...
}
}```

##### Share on other sites

I'm confused.   What are you trying to make the root prim do?   Do you want to rotate it so that's rotated at a particular angle ("turn to 90 degrees")  or do you want to rotate it through 90 degrees from whatever angle it's rotated at?

Also,

`vector xyz_angles = <0,0.90,0>; // This is to define a 90 degree change﻿`

looks wrong to me.   Shouldn't it be  rot_yyzq = llEuler2Rot(<0.0, 90.0, 0.0>*DEG_TO_RAD);  ?

##### Share on other sites

I'm not sure why you are applying /llGetRootRotation here.  If you want to rotate the root prim by rot_xyzq, all you should need is

llSetRot( rot_xyzq * llGetRot() );  (In your case, that should be the same as llSetRot( llEuler2Rot(0.0,0.0,PI/2) * llGetRot() );  )

When you divide by llGetRootRot, you are trying to apply a local rotation, which doesn't make any sense for the root prim.  I'm not sure what your formulation produces, but it's not a simple rotation in region coordinates.

##### Share on other sites

I'm not trying to rotate the root prim. I'm trying to rotate a child prim when the child prim is clicked. Eventually I want a couple of the child prims to rotate individually when each is clicked. I can obtain the results I want by using separate scripts in each child prim, but I would prefer to use one script in the root.

##### Share on other sites

Oh, if that's the case, then get the link number of the link that was clicked (  iLink = llDetectedLinkNumber(0) ) and then get its local rotation (  rRotChild = llList2Rot(llGetLinkPrimitiveParams(iLink,[PRIM_ROT_LOCAL]),0) ), calculate the new rotation ( rNewRotChild = llEuler2Rot(<0.0,0.0,PI/2>) * rChildRot  -- or whatever rotation you want to apply) and apply it  ( llSetLinkPrimitiveParamsFast(iLink,[PRIM_ROT_LOCAL,rNewRotChild] ) ).

Edited by Rolig Loon
typo, of course

##### Share on other sites

I think that last way is gonna work. Initial tests are good. Thank you both for your help. I tried so many methods of the same command and it just wasn't working correctly.

##### Share on other sites

No matter how long you have been doing this, it's still easy to get all twisted around by rotation problems. For me, the Stand-Back-And-Take-A-Fresh-Look question is usually, "Am I looking at this problem in the right frame of reference?"  The answer is often "Oh crap, not again."

Good luck.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.