# Script for rotating Cube?

## Recommended Posts

I accidantly post this tread in the wrong forum i guess...haven't saw the script section. My bad :(

I found that OmegaTarget script, but it does not work a I want to. The final result should look like this:

http://www.shutterstock.com/video/clip-2933809-stock-footage-abstract-rotating-cube-loop-able-d-anim...

If I turn the cube the rotation axes goes with the object and doesn't stay an the z-axis to earth. Its for a logo in front of a building. The cube should spin on a corner and not an the flat side.... but I just can't get it to work with the omega script. Beside I am a totally noob on scripting. Hope somebody can help.

and sry for my bad english

##### Share on other sites

You have to do a trick here. Prims rotate around their centre, at least with Omega they do. But you want it to rotate on a corner. So you have to cut the prim so that the centre looks like it is a corner. Rez a prim and on the Object tab in Edit set the rotation to x=45 y=0 z=45

Now set Path Cut to B 0.375 E 0.625 and Slice B to 0.5

default
{
state_entry()
{
// x y z speed acceleration
llTargetOmega(<0,0,1>,1.0,0.001);
}

}

##### Share on other sites

First rotating the cube on a point and then starting llTargteOmega() works aswell.
Just dump this script in a prim.

`default {    state_entry() {        llSetRot(llEuler2Rot(<35.264, 45.0, 0.0> * DEG_TO_RAD));        llTargetOmega(<0,0,1>, PI/4, 1.0);    }}`

##### Share on other sites

You can use 2 prims.

The small invisible root will rotate and the big cube you can link to it in any angle you want.

##### Share on other sites

I figured it out some time after my post. I just build a pyramid with the omega script and linked the cube. Sometimes the solutions are so easy that you don't see them.

##### Share on other sites

I would simply tell the script to  position the cube as I wanted it, and then rotate it on the region's z axis rather than that of the cube.

Thus:

`default{    state_entry()    {        rotation rot = llRotBetween(<1.0,1.0,1.0>,<0.0,0.0,1.0>); //find the angle between the cube's centre and the vertical up        llSetRot(rot); //rotate it to that angle               float speed = (TWO_PI/4.0); // one rotation every 4 seconds       llTargetOmega( <0.0,0.0,1.0>, speed,0.1);           }}`

ETA  I think this is the same as Ron's solution, but mine is a bit more verbose and explicit about the steps involved.

##### Share on other sites

That's assuming that the object to be rotated is in fact a cube.  If you squish or elongate the cube along any of its axes, the body diagonal will no longer be <1,1,1>.  You''l have to add a correction and then change one line in Innula's script ...

`vector vBody = llGetScale();rotation rot = llRotBetween(vBody,<0.0,0.0,1.0>); //find the angle between the body diagonal and the +Z axis`

##### Share on other sites

Thanks, Rolig.   I hadn't considered what to do if it's not a cube, but you're right, of course.

This is one of the things I really like about the Scripting Forum -- someone asks a specific question, and we sometimes end up with a method that's generally applicable and many people must have wondered about in the past.    In fact, I think I remember asking a similar question (at least about how to get the cube resting on its corner) ages ago, soon after I started learning to script, and Dora answering it.

## 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.