Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Hovering

Jaydin Normandy
Registered User
Join date: 1 Apr 2006
Posts: 19
07-07-2008 11:16
I need an object to bounce up and down like it is hovering there. I tried this code but it is very jerky and I need it to be smooth. Is there anyway to do this?


integer x = 1;
float i = .01;

default
{
state_entry()
{
llSetTimerEvent(.001);
}

timer()
{

if(x == 1)
{
i *= 1.3;
llSetPos(llGetPos() + <0,0,i>;);
if(i > .07)
{
x = 0;
}
}
else
{
i /= 1.3;
llSetPos(llGetPos() - <0,0,i>;);
if(i <= .01)
{
x = 1;
}
}
}

}
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
07-07-2008 15:52
If you want smooth movement you need to use the physics functions. I'd suggest starting with the Wiki and learning about SL physics, all I remember is that there are some specific things you need to know in order to be able to use it effectively.
Johan Laurasia
Fully Rezzed
Join date: 31 Oct 2006
Posts: 1,394
07-07-2008 17:29
If you're looking to hover with a slight bouncing motion, I'd go physical as well, use llSetStatus (STATUS_PHYSICS, TRUE); to set to physical, and set the buoyancy to 1.0 (llSetBuoyancy(1.0);) to make the object buoyant. Then, perhaps a slight push from the top every so often (use a timer event), to push it downward, then pause while it rebounds. (llApplyImpulse() perhaps?).

http://www.secondscripter.com
_____________________
My tutes
http://www.youtube.com/johanlaurasia
Jaydin Normandy
Registered User
Join date: 1 Apr 2006
Posts: 19
07-08-2008 12:29
Is there anyway to make it physics without a user being able to run into it and moving it everywhere?
Squirrel Wood
Nuteater. Beware!
Join date: 14 Jun 2006
Posts: 471
07-08-2008 23:33
Without using physics you can get this to be "smoother" in a sense by using llSin().

Basically you have:

vector CenterPos = llgetPos();
float Offset = 2.0; // 2m up/down
float Angle = 0.0;

and in your timer event you have:

timer()
{
Angle += 0.01;
if (Angle > TWO_PI) {Angle -= TWO_PI;}
llSetPos(CenterPos + <0,0,llSin(Angle) * Offset>;);
}

Also, any timer event set to less than 0.01 will trigger at a minimum time of 0.01s. Also some functions force the script to sleep for a certain time. Like, 0.2s for example. In which case it makes no sense to set the timer event to anything less than the combined sleep time of all commands with a forced sleep time used within the timer event.