Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help with bridge script EASY FOR CODER $$$

Count Burks
Registered User
Join date: 14 Feb 2007
Posts: 1,089
08-18-2007 15:21
I have an object, a bridge (rope bridge to be exact). It consists out of 160 prims.

To make it more real I want to add a little script to it so when somebody steps on the bridge to cross it the bridge starts slowly swinging from let to right while the avatar walks over it. When the avatar steps of the bridge the bridge stops swinging.

This should be easy for any coder, a quick programming job.

I also want to include a sound in the script to make it even more realistic.

I found this bit of code to help you on the way if needed:

integer spinning = 1;
default
{
touch_start(integer total_number)
{
if (! spinning)
llTargetOmega( < 0, 0, 0 >, 0, 0);
else if (spinning == 2)
llTargetOmega( < 0, 0, 0 >, 0, 0);
else if (spinning == 1)
llTargetOmega( < 0, 0, 1 >, PI, 1.0);
else
llTargetOmega( < 0, 0, 1 >, -PI, 1.0);
spinning = spinning + 1;
if (spinning == 4)
spinning = 0;
}
}


This is what this code does:

What this does is makes the object do this, advancing one item each time it is pressed:

Start turning one direction
Stop
Turn the opposite direction to number 1
Stop
After step 4, the next press starts the loop again.


So instead of touch start it should start when an avatar steps on the linked object.

The spinning should rotate in a certain way from one side to the other by a certain amount of degrees at a certain speed and stop when the avatar walks of the bridge.

The sound should start playing when the avatar steps on the bridge and loop with an interval of 2 or 3 seconds untill the avatar leaves the bridge.

Easy for any coder, I can provide you with the bridge and the sound. If you want Lindens send a PM on the forums or just post in here please. Don't IM me in SL.

Thank you,


Count Burks
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-06-2008 15:06
From: Count Burks

default
{
touch_start(integer total_number)
{

well it looks like you could change the touch_start to collision_start, but you'll need to play with it some more to get it right. it started spinning, not really swaying as you suggest, but each step is a collision really, so it can stop and start randomly as they're walking, and leave it spinning when they step off if their last step on it wasn't one to turn it off
try searching the forum for a swing script, i believe void singer posted a pretty good one, i've used it, but it's been a while, but i'm sure you could do as i said just now about changing the touch to collision, i'll try it as well and post it if it works right for me. not exactly sure how experienced you are with building/scripting, in most cases the scripts effect the parent prim, especially rotations, so be careful which one you make the parent or the bridge will move funny lol
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
05-06-2008 15:33
ok, so i got it working the way i assume you wanted it to, here's the script i used, i don't know if this is the one from void, but it works. you may need to play with the distance and timetotake to get it to swing how you want, and if your bridge is laying down the Y axis, unlike mine which is on the Xaxis, you;ll need to change the target omega vector to <0,1,0>, and the vrot.x to vrot.y. hope this helps:

CODE

float distance = .5;
float timetotake = 4;
float speed;
rotation backrot;
rotation forerot;
rotation stoprot;

startSwing()
{
vector vDir;

speed = distance / timetotake;
// llOwnerSay("Speed = " + (string)speed + " at start");
llSetTimerEvent(timetotake);
vDir = llRot2Up(llGetRot());
llSetRot(stoprot);
llTargetOmega(<1,0,0>, -distance / ( 2 * timetotake ), 1.0 );
}

swingchange()
{
vector vDir = llRot2Up(llGetRot());

// llOwnerSay("timer(): gain=" + (string)gain);
// llTargetOmega( <0,0,0>, speed, 1.0 );
if( speed < 0 ) {
llSetRot(backrot);
} else {
llSetRot(forerot);
}
llTargetOmega( <1,0,0>, speed, 1.0 );
speed = 0 - speed;
}

integer swinging = 0;

default
{
on_rez(integer sp)
{
llResetScript();
}

state_entry()
{
rotation rrot = llGetRot();
vector vrot = llRot2Euler( rrot );
stoprot = rrot;
vrot.x += distance/2;
backrot = llEuler2Rot( vrot );
vrot.x -= distance;
forerot = llEuler2Rot( vrot );

// vector vrot = llRot2Euler( llGetRot() );
// vrot.z = (distance/2);//2 * speed;
// backrot = llEuler2Rot( vrot );
// vrot.z = -(distance/2);//-2 * speed;
// forerot = llEuler2Rot( vrot );
llTargetOmega(<0,0,0>, 0, 0.0);
swinging = 0;
// vrot.z = 0;
// stoprot = llEuler2Rot( vrot );
// llSetRot( stoprot );
// llOwnerSay("Backrot: " + (string)backrot + ", forerot: " + (string)forerot);
}

timer()
{
swingchange();
}

collision_start(integer total_number)
{
if( swinging > 0 ) {
swinging = 0;
llSetTimerEvent(0.0);
llTargetOmega(<0,0,0>, 0, 0.0 );
llSetRot(stoprot);
llTargetOmega(<0,0,0>, 0, 0.0 );
} else {
swinging = 1;
startSwing();
}
}

moving_end()
{
llSleep(2.0);
llResetScript();
}
}
[PHP/]
Count Burks
Registered User
Join date: 14 Feb 2007
Posts: 1,089
06-05-2008 20:16
Thank you, it's like 10 months after I posted it but I will take a look at it.

Count Burks