I'm at work and can't test this, but here is how I would approach it:
Start with a vector that points in the direction of the forward X axis of the boat:
vector fwd = <1,0,0>*llGetRot();
(What? You didn't build your ship to have the X axis pointing forward? That will make things difficult. Most people solve this problem by adding a new prim that does have X pointing forward and making that prim the root prim. Rotation will be around the center of that prim as well, a nice feature since careful placement of that prim will set the center of rotation where you want it).
Construct an “up” vector that is randomly tilted fore-aft back and forth:
vector up = llVecNorm(<llFrand(0.1),llFrand(0.1),1>);
(note that his tilts at maximum angle of atan(.1) or 5.7 degrees, change that number to set the tilt)
(note: if you want different rocking fore/aft from port/starboard and you use different value for the two random numbers, you will want to multiply the resulting vector by llGetRot() to align it with the axis of the boat).
Now you use my FAVORITE LSL function call, llAxes2Rot to turn that back into a rotation:
llSetRot(llAxes2Rot(fwd,up%fwd,up));
Do this in the timer() event, set it up to run once a second, and your ship will totally ROCK!
OK, I snuck in-world from work and tested it. Turns out I DID misspell llAxes2Rot the first time. I fixed that and the following script rocks the boat nicely:
Code:
default
{
state_entry()
{
llSetTimerEvent(1);
}
timer()
{
vector fwd = <1,0,0>*llGetRot();
vector up = llVecNorm(<llFrand(0.1),llFrand(0.1),1>);
llSetRot(llAxes2Rot(fwd,up%fwd,up));
}
}