Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Simple floating script available?

Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
07-26-2007 20:17
I made a simple raft for the water on my beach.. if there a simple script I can drop into it, so it floats up and down a little, looking like it is floating on the water?

I tried a few things here, but nothing worked.
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
07-27-2007 10:23
You might be able to just use something reallly basic like, depending how fancy you want it. This is just a rough outline, you could tweak it significantly for a more organic feel.. perhaps incorporate some random values and variance between waves etc. But just as a general idea:

// wave height
float BOB_DISTANCE = 0.1;

// estimate of time it takes to bob from top of wave to bottom of wave
// larger numbers will slow movement, smaller numbers will speed it
float BOB_TIME = 2;

// frequency that waves occur
float TIME_BETWEEN_BOBS = 5;

// current state information
integer UP = 1;
integer DOWN = 2;
integer CURRENT_POSITION = UP;

bob(integer direction)
{
if(direction == UP)
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE>, BOB_TIME);
else
llMoveToTarget(llGetPos()+<0,0,-BOB_DISTANCE>, BOB_TIME);
}
default
{
state_entry()
{
//initial move to put raft at top of a wave
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE/2>, 0.1);
llSetTimerEvent(TIME_BETWEEN_BOBS);
}
timer()
{
if(CURRENT_POSITION == UP)
bob(DOWN);
else
bob(UP);
}
}
Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
07-27-2007 13:31
I'll try this, and see how it looks. My scripting skills are more hacking existing ones that are out there, so they are pretty poor.

Basically, it would just need to raise and lower, and maybe tiilt back on the raise, and foreward a little on the decline.

I'll see how this looks...and thanks!
Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
07-27-2007 13:35
Hmm added that, and nothing happens at all.
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
07-27-2007 15:34
llMoveToTarget works only on physical objects, if your object was not already physical and buoyant it would definitely not work.

add these lines to the state entry:

llSetBuoyancy(1.0);
llSetStatus(STATUS_PHYSICS,TRUE);

give that a go.
Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
07-27-2007 16:17
Tried this: but I get a syntax error.. did I add it improperly?

(I'm just dropping it into a prim for testing)

// wave height
float BOB_DISTANCE = 0.1;

// estimate of time it takes to bob from top of wave to bottom of wave
// larger numbers will slow movement, smaller numbers will speed it
float BOB_TIME = 2;

// frequency that waves occur
float TIME_BETWEEN_BOBS = 5;

// current state information
integer UP = 1;
integer DOWN = 2;
integer CURRENT_POSITION = UP;

bob(integer direction)
{
if(direction == UP)
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE>, BOB_TIME);
else
llMoveToTarget(llGetPos()+<0,0,-BOB_DISTANCE>, BOB_TIME);
}
default
{
state_entry()
llSetBuoyancy(1.0);
llSetStatus(STATUS_PHYSICS,TRUE);
{
//initial move to put raft at top of a wave
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE/2>, 0.1);
llSetTimerEvent(TIME_BETWEEN_BOBS);
}
timer()
{
if(CURRENT_POSITION == UP)
bob(DOWN);
else
bob(UP);
}
}
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
07-27-2007 16:23
I just typed this up w/o trying inworld so there's likely just some braindead typos in there, what line is giving an error? If you click on the error in the script editor it should take you to the line.
Shadow Subagja
Registered User
Join date: 29 Apr 2007
Posts: 354
07-27-2007 16:30
I do see an error in the state_entry.

THIS
state_entry()
llSetBuoyancy(1.0);
llSetStatus(STATUS_PHYSICS,TRUE);
{
//initial move to put raft at top of a wave
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE/2>, 0.1);
llSetTimerEvent(TIME_BETWEEN_BOBS);
}


SHOULD BE
state_entry()
{
//initial move to put raft at top of a wave
llSetBuoyancy(1.0);
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE/2>, 0.1);
llSetTimerEvent(TIME_BETWEEN_BOBS);
}

The {}'s encapsulate the code for a function or state.

From: Gareee Taov
Tried this: but I get a syntax error.. did I add it improperly?

(I'm just dropping it into a prim for testing)

// wave height
float BOB_DISTANCE = 0.1;

// estimate of time it takes to bob from top of wave to bottom of wave
// larger numbers will slow movement, smaller numbers will speed it
float BOB_TIME = 2;

// frequency that waves occur
float TIME_BETWEEN_BOBS = 5;

// current state information
integer UP = 1;
integer DOWN = 2;
integer CURRENT_POSITION = UP;

bob(integer direction)
{
if(direction == UP)
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE>, BOB_TIME);
else
llMoveToTarget(llGetPos()+<0,0,-BOB_DISTANCE>, BOB_TIME);
}
default
{
state_entry()
llSetBuoyancy(1.0);
llSetStatus(STATUS_PHYSICS,TRUE);
{
//initial move to put raft at top of a wave
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE/2>, 0.1);
llSetTimerEvent(TIME_BETWEEN_BOBS);
}
timer()
{
if(CURRENT_POSITION == UP)
bob(DOWN);
else
bob(UP);
}
}
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
Sinking Raft
08-31-2007 07:52
I was curious to try out this script in world. But the raft doesnt bob, it slowly sinks lower and lower, never bobbing back up.



CODE

// wave height
float BOB_DISTANCE = 0.1;

// estimate of time it takes to bob from top of wave to bottom of wave
// larger numbers will slow movement, smaller numbers will speed it
float BOB_TIME = 1;

// frequency that waves occur
float TIME_BETWEEN_BOBS = 1;

// current state information
integer UP = 1;
integer DOWN = 2;
integer CURRENT_POSITION = UP;

bob(integer direction)
{
if(direction == UP)
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE>, BOB_TIME);
else
llMoveToTarget(llGetPos()+<0,0,-BOB_DISTANCE>, BOB_TIME);
}
default
{
state_entry()
{
//initial move to put raft at top of a wave
llSetBuoyancy(1.0);
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE/2>, 0.1);
llSetTimerEvent(TIME_BETWEEN_BOBS);
}

timer()
{
if(CURRENT_POSITION == UP)
bob(DOWN);
else
bob(UP);
}
}

_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Sharp Pike
Registered User
Join date: 24 Oct 2006
Posts: 12
08-31-2007 08:01
Try replacing the timer function with this.

timer()
{
if(CURRENT_POSITION == UP)
{
CURRENT_POSITION = DOWN;
bob(DOWN);
}
else
{
CURRENT_POSITION = UP;
bob(UP);
}
}
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
08-31-2007 08:46
Thanks Sharp, That works much better, I'm going to leave it running awhile and see how it does.
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
08-31-2007 08:49
glad this is being revisited. Is it possible to add a tilt back going down, and a tilt foreward going up, to more simulate wave movement?
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
Like a balloon....
08-31-2007 12:14
Search for the balloon thread. Same problem exactly, with a simple solution.
Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
08-31-2007 15:31
I tried replacing the timer function, but get a syntax error.. here's what I have:

// wave height
float BOB_DISTANCE = 0.1;

// estimate of time it takes to bob from top of wave to bottom of wave
// larger numbers will slow movement, smaller numbers will speed it
float BOB_TIME = 1;

// frequency that waves occur
float TIME_BETWEEN_BOBS = 1;

// current state information
integer UP = 1;
integer DOWN = 2;
integer CURRENT_POSITION = UP;

bob(integer direction)
{
if(direction == UP)
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE>, BOB_TIME);
else
llMoveToTarget(llGetPos()+<0,0,-BOB_DISTANCE>, BOB_TIME);
}
default
{
state_entry()
{
//initial move to put raft at top of a wave
llSetBuoyancy(1.0);
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE/2>, 0.1);
llSetTimerEvent(TIME_BETWEEN_BOBS);
}

timer()
{
if(CURRENT_POSITION == UP)
{
CURRENT_POSITION = DOWN;
bob(DOWN);
}
else
{
CURRENT_POSITION = UP;
bob(UP);
}
}

the error comes up at the last bracket in the script

I added an additional bracket at the bottom and it compiles, but still only goes down, not back up
Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
08-31-2007 15:39
I also just tried the baloon script, but it syntax errors when compiling.. if you ignore that, it drops like a rock, with a slight bounce
ArchTx Edo
Mystic/Artist/Architect
Join date: 13 Feb 2005
Posts: 1,993
09-02-2007 11:46
The bobbing works ok with this script now, but after I left it running for 3 or 4 hours it ended up floating 9.8 meters in the air. It gradually gains altitude as it bobs up and down.

CODE


// wave height
float BOB_DISTANCE = 0.1;

// estimate of time it takes to bob from top of wave to bottom of wave
// larger numbers will slow movement, smaller numbers will speed it
float BOB_TIME = 1;

// frequency that waves occur
float TIME_BETWEEN_BOBS = 1;

// current state information
integer UP = 1;
integer DOWN = 2;
integer CURRENT_POSITION = UP;

bob(integer direction)
{
if(direction == UP)
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE>, BOB_TIME);
else
llMoveToTarget(llGetPos()+<0,0,-BOB_DISTANCE>, BOB_TIME);
}
default
{
state_entry()
{
//initial move to put raft at top of a wave
llSetBuoyancy(1.0);
llSetStatus(STATUS_PHYSICS,TRUE);
llMoveToTarget(llGetPos()+<0,0,BOB_DISTANCE/2>, 0.1);
llSetTimerEvent(TIME_BETWEEN_BOBS);
}


timer()
{
if(CURRENT_POSITION == UP)
{
CURRENT_POSITION = DOWN;
bob(DOWN);
}
else
{
CURRENT_POSITION = UP;
bob(UP);
}
}
}
_____________________

VRchitecture Model Homes at http://slurl.com/secondlife/Shona/60/220/30
http://www.slexchange.com/modules.php?name=Marketplace&MerchantID=2240
http://shop.onrez.com/Archtx_Edo
Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
09-02-2007 12:30
that does work here, but the prim also rotates around randomly too much. My original idea was to put it in a prim floating chair, for our beachfront property, but if you sit on the prim as it is, you end up upside down in no time.

It would work though for a flaoting beach ball, maybe transmapped clouds, or something y
you want reletivly statiionary, but with some floating or random movement.

Might be interesting with some flexi parts attached as well.

One error with this, it seems the "down" or "up" is sometimes duplicated 2 or 3 times, before switching to the opposite, so over time, the prim "sinks' or rises.
Phate Shepherd
Addicted to code
Join date: 14 Feb 2008
Posts: 96
06-24-2008 11:24
I would think the safer thing to do (to avoid slowly creeping in one direction or the other) would be to set a global vector on rez that holds the position, and then use the llMoveToTarget to always use that global +/- the bob offset. There should never be any drift that way.

Since this script is always referencing the "current" position of the object, rather than the rezzed position, there will always be drift.
Gareee Taov
Registered User
Join date: 8 Jan 2007
Posts: 117
06-24-2008 15:55
No one (to my knowledge) ever came up with a simple bobbing script at all.
Lordly Binder
Registered User
Join date: 29 May 2007
Posts: 4
Buoyancy is barfed
07-12-2008 18:23
I have made a ball of hollowed out plastic and used physics and llSetBuoyancy(1.0);

But the ball seems to float away slowly up until it reaches the end of the sim. Does anybody know what the proer value is. 0.95 makes it sink (and none too slowly) in the water.

This is pretty confusing.

Thanks for any advice.

Lordly
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
07-15-2008 10:39
Have you given llSetHoverHeight() a try?

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llSetHoverHeight