Jump to content

water buoyancy and flotation script


Recommended Posts

Hello , I am looking for a script that could let my boat to float and rock and look like is buoyancy on water.

I bought and tried many scripts and all look bad, robotic , not smooth , jaccy or need a reset after a while, some after I run after some days stop work and show them above water...

I noticed a good one in one of the objects I bought recently for a buoy that looks good but is not on sale , so can anywone help me make a good one or point me where to find one?

 

I need that for an item to put people on sit and cuddle . not a vehicle.

 

Edited by Naiman Broome
Link to comment
Share on other sites

llSetHoverHeight() might be what you're looking for? you might also want to use llLookAt to keep the thing upright, and llMoveToTarget() to keep the thing in place.

Untested:

default()
{
  state_entry()
  {
    vector Home = llGetPos();
    //you can set to physical with llSLPPF, but I'm too lazy to wright that out.
    llSetHoverHeight(-0.2,TRUE,1.0);
    llLookAt(Home+<0,0,1>,0.5,3.0);
    //llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z,FALSE);
    // ^^ if you don't want it to rotate at all.
    llMoveToTarget(Home,5.0);
  }
}

 

Edited by Quistessa
  • Like 1
Link to comment
Share on other sites

2 minutes ago, Naiman Broome said:

thanks but how  Iadd the gentle  roll , yaw and the pitch?

You don't, at least not easily. Ideally you set some physics parameters as above and let the simulation take care of the exact orientation for you.

Link to comment
Share on other sites

Nothing a couple sine-waves can't solve. It's a little leaky, but I did my best.

float t = llGetTime();

// Direction pointing upwards (2 meters),
// including with some arbitrary horizontal offset (tilt).
float tilt = llCos(t/2) * 0.15;
vector normal = llVecNorm(<tilt, tilt, 2>);
rotation r = llRotBetween(<0,0,1>, normal);

// Gentle waves
float height = llCos(t) * 0.1;

llSetLinkPrimitiveParamsFast(LINK_THIS, [
    PRIM_ROTATION, r,
    PRIM_POSITION, pos + <0,0,height>
]);

 

Edited by Wulfie Reanimator
  • Like 4
Link to comment
Share on other sites

7 hours ago, Wulfie Reanimator said:

Nothing a couple sine-waves can't solve. It's a little leaky, but I did my best.


float t = llGetTime();

// Direction pointing upwards (2 meters),
// including with some arbitrary horizontal offset (tilt).
float tilt = llCos(t/2) * 0.15;
vector normal = llVecNorm(<tilt, tilt, 2>);
rotation r = llRotBetween(<0,0,1>, normal);

// Gentle waves
float height = llCos(t) * 0.1;

llSetLinkPrimitiveParamsFast(LINK_THIS, [
    PRIM_ROTATION, r,
    PRIM_POSITION, pos + <0,0,height>
]);

 

Tried that in a prim but seems immoblile without moving , I am missing something?

Link to comment
Share on other sites

3 hours ago, Naiman Broome said:

Tried that in a prim but seems immoblile without moving , I am missing something?

It isn't a complete script, you will have to put that into a loop or a timer. If you only ran that code once, it would change the object's position/rotation once.

  • Like 1
Link to comment
Share on other sites

Just now, Wulfie Reanimator said:

It isn't a complete script, you will have to put that into a loop or a timer. If you only ran that code once, it would change the object's position/rotation once.

can u make a sample of how to ? I am not expert in this, also what means leaky?

Link to comment
Share on other sites

Create a new script.

This will give you the basic default state script with a touch event.

Add a second event inside the default, just below the touch_start, called timer.

Put Wulfie's snippet inside the timer event.

inside state entry, add a line llSetTimerEvent(0.5);

The timer will activate very half second, giving a very slow up and down motion

(note, not tested in-world )

default
{
    state_entry()
	{
		llSetTimerEvent(0.5);
	}
	touch_start...
	{

	}
	timer
	{
	// put Wulfie's snippet in here
	}
}

To ve very clever, you can then create a global variable called something like rock, initially set to 1. When you touch the prim, if rock ==1 set the timer ev

Edited by Profaitchikenz Haiku
Link to comment
Share on other sites

25 minutes ago, Mollymews said:

the posted code snippets demo the logic

look up the syntax for each of the events and functions on the lsl wiki: http://wiki.secondlife.com/wiki/LSL_Portal

and type the correct syntax for each into your script

I did, or tried, but as I said I am not a scripter, nor I have the time to beging studying the whole scripting, I just wanted to find a good float, rock , smooth script because the ones I bought aren't good and can't find anything else around.

Link to comment
Share on other sites

Ok I fixed it even more, but , I do not understand how to fine tune, the Vector and the Rotation , As the description on the wiki is pretty scarce...

 

for example which one is x y and z?

 

Why use tild in the first two parameters?

And how I cange the direction of tilting when rezzed?

  • Like 1
Link to comment
Share on other sites

5 hours ago, Naiman Broome said:

I did, or tried, but as I said I am not a scripter, nor I have the time to beging studying the whole scripting, I just wanted to find a good float, rock , smooth script because the ones I bought aren't good and can't find anything else around.

If you want someone to wright the most perfect amazing floating script that works exactly how you want it to, you either need to write it yourself(free), find it on the MP or elsewhere(least expensive) or pay someone else to write it for you (most expensive).

The LSL scripting forums are for discussing the various techniques and ideas for how to do things, not a place to extract free labor . </rant>

  • Like 1
Link to comment
Share on other sites

6 hours ago, Naiman Broome said:

for example which one is x y and z?

There is an SL convention that vectors and quaternions (rotations) use the implicit order  X Y Z in their arguments. In the LSL portal this is probably buried in the section "Types"

7 hours ago, Naiman Broome said:

I am getting syntax error even when I copy scripts from LL lib.

This is most likely because you are either copying a snippet (ie an incomplete script) or you have missed a bracket at the very end of a multi-line chunk that is in a window with vertical scroll bars

For the first, get into the habit of viewing the script first of all as chunk, there must be a "default" in the body of text, it must have an opening "{" and at the end of all the events a closing "}"

When copying a script from the wiki, position the cursor at the very top of the code, then use Ctrl-A to select everything including any portions hidden by the limited extents of the window.

6 hours ago, Naiman Broome said:

Why use tild in the first two parameters?

I suspect Wulfie is allowing the boat to roll from side to side (possibly the X axis) and rock from stem to stern (possibly the Y axis), which is OK for a coracle or multi-hull but not for a classic displacement hull. My feeling is that the stem-to-stern motion when the boat is not underway should be much less than the side to side rolling , perhaps a fifth (if that).of the side to side. try reducing the amount of tilt in one of the two axes ( use tilt * 0.2) and seeing what the effect is.

A more precise determination is to rezz the boat, edit it, and see which way the axes are. If the X-axis (red) goes from stern to stem then this is the axis around which the boat will roll from side to side,

Edited by Profaitchikenz Haiku
  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Profaitchikenz Haiku said:
7 hours ago, Naiman Broome said:

Why use tilt in the first two parameters?

I suspect Wulfie is allowing the boat to roll from side to side (possibly the X axis) and rock from stem to stern (possibly the Y axis), which is OK for a coracle or multi-hull but not for a classic displacement hull. My feeling is that the stem-to-stern motion when the boat is not underway should be much less than the side to side rolling , perhaps a fifth (if that).of the side to side. try reducing the amount of tilt in one of the two axes ( use tilt * 0.2) and seeing what the effect is.

My goal was to show a simple approximation of a floating object bobbing in the waves.

The most basic thing to do is to oscillate the object up and down according to a simple wave-function.

To add a little more complexity, you can also approximate how the object might tilt in the waves, but this is highly dependent on the mass and shape of the object, so I did not make any assumptions. Instead, I only calculated one value and applied it equally on the world's X and Y axes, which makes the object always tilt back and forth diagonally (relative to the world, not the object's own orientation).

If you wanted higher waves, change the multiplier:

float height = llCos(t) * 0.1;

If you want greater tilt, change the multiplier and/or the height of the vector:
Or if you want a faster rate of tilt, increase the value given to llCos.

float tilt = llCos(t/2) * 0.15;
vector normal = llVecNorm(<tilt, tilt, 2>);

 

Edited by Wulfie Reanimator
  • Thanks 1
Link to comment
Share on other sites

17 minutes ago, Wulfie Reanimator said:

Instead, I only calculated one value and applied it equally on the world's X and Y axes, which makes the object always tilt back and forth diagonally

I think it would be perfectly good enough if you used the beam and waterline length as multipliers, so the amount of roll is proportional to the beam/length. SL is an approximation at best. But only the OP can work out which is beam and which is length axes, as we cannot see the build details.

Regarding your simple wave-function, I gotta ask, is the cat alive or dead?

Edited by Profaitchikenz Haiku
  • Like 1
Link to comment
Share on other sites

Thankyou , I have playied with the setting and I managed to improve the motion , I am wondering though :

 

1 Using the timer causes any performance problems to the sim or else?

2 How I do to fix the fact that once the script runs , then I cannot turn the boat or whatever it is in any other direction of tilt and it snaps back into its position , I suspect that could be couse I am using world coordinates? And not perhaps local ones ? Its good to use the world coordinates for the height and position , I have infact added a way to move the center of mass to the water level , but I am not sure how to do to avoid the snapping back into position when I rotate the object or I move it , any ideas?

Link to comment
Share on other sites

26 minutes ago, Naiman Broome said:

2 How I do to fix the fact that once the script runs , then I cannot turn the boat or whatever it is in any other direction of tilt and it snaps back into its position , I suspect that could be couse I am using world coordinates? And not perhaps local ones ? Its good to use the world coordinates for the height and position , I have infact added a way to move the center of mass to the water level , but I am not sure how to do to avoid the snapping back into position when I rotate the object or I move it , any ideas?

times r by the initial rotation of the object

// global var rot
rotation rot;

state_entry()
{
   rot = llGetRot();
   ... other codes ...
}

timer()
{
  ...
  rotation r = llRotBetween(<0,0,1>, normal) * rot;
  ...
}

 

Edited by Mollymews
  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...