Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Vibration plus movement solid ball

GuanPeng Woodrunner
Registered User
Join date: 12 Jul 2009
Posts: 11
09-02-2009 00:48
Hello everybody, I've been trying this script out for ages, and I am still stuck with it. I need to make a few balls collide with each other, and when it happens it will vibrate and move towards the left side (X-axis), and move back to the right side(X-axis) again and back to left etc.

The coding is as follow:
CODE

bounce()
{
while(1)
{
vector f = <-0.002,0.001,0.001>;
llApplyRotationalImpulse(f * llGetMass(), FALSE);
}

}

default
{
state_entry()
{
llSetStatus(STATUS_PHYSICS, TRUE);
}

collision(integer total_number)
{
bounce();
}
}
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
09-02-2009 01:20
I've not used these functions myself yet, but doesn't llApplyRotationalImpulse just cause it to rotate about its own axis? Perhaps llApplyImpulse would do what you want.

Also, won't while (1) will create an infinite loop? And to create a vibration effect, I suspect you will need to reverse the direction of the impulse periodically.

This example seems to do what you want, but the period of the vibration is probably far too slow. I'm sure other scripters in this forum will be able to describe a far better method.

CODE

Vibrate ()
{
vector position = llGetPos ();
integer counter = 0;
do
{
llSetPos (position + <0.1 * (counter % 2) * (1.0 / (float) counter), 0.0, 0.0>);
} while (++counter < 10);
}

default
{
touch_start(integer total_number)
{
Vibrate ();
}
}
Dora Gustafson
Registered User
Join date: 13 Mar 2007
Posts: 779
09-02-2009 01:35
From: GuanPeng Woodrunner

CODE

bounce()
{
while(1)
{
vector f = <-0.002,0.001,0.001>;
llApplyRotationalImpulse(f * llGetMass(), FALSE);
}
}

default
{
state_entry()
{
llSetStatus(STATUS_PHYSICS, TRUE);
}

collision(integer total_number)
{
bounce();
}
}

The "while(1)" construct is BAD! The SIM will get stuck in it and no further events will be handled! On top of that, it will create LAG by putting a constant load on the SIM:(
_____________________
From Studio Dora
GuanPeng Woodrunner
Registered User
Join date: 12 Jul 2009
Posts: 11
09-02-2009 20:40
It's my bad for not explaining thoroughly! Geez, my purpose is to make the ball move left and right while vibrating. Perhaps using the movement of solid particles to describe the desired movement of the ball would be the closest explanation I can get.

I'll want to make the ball move + vibrate infinitely, which explains why I need the while loop.
Oh, I forgot to add in! It is contained in a container whereby the ball vibrates + moves with other similar balls.

The while loop should be put inside the collision method actually. So, anyone who can help me?
EF Klaar
Registered User
Join date: 11 Jun 2007
Posts: 330
09-03-2009 00:54
From: GuanPeng Woodrunner
I'll want to make the ball move + vibrate infinitely, which explains why I need the while loop.
Oh, I forgot to add in! It is contained in a container whereby the ball vibrates + moves with other similar balls.

The while loop should be put inside the collision method actually. So, anyone who can help me?

As Dora says, an infinite while loop will stop the script from doing anything else. A multitude of infinite while loops will lag a sim to a standstill. This may be acceptable if you own the sim yourself, but is likely to result in abuse reports and bans if you do not. You would probably need to use a timer loop to move the ball first one way and then the other, but this too sounds like a recipe for lagging a sim when apllied to a large number of objects, and is therefore something I had best leave to an expert.
GuanPeng Woodrunner
Registered User
Join date: 12 Jul 2009
Posts: 11
09-03-2009 01:00
Okay, thanks a lot Klaar! I'll need to find more help from experts!