Pages

Sunday, May 16, 2010

Collision Detection Goodness

Nettrice had a couple of questions but I've had a long weekend and I'm draggin so I'm going to answer her second question first and save the other one for tomorrow.

Her question was in regards to making part of a ramp/walkway light up as the avatar touches those certain parts, similar to the piano keys you play by walking on (e.g. Tom Hanks in Big).

You can achieve this with just a few lines of code.

default
{
    state_entry()
    {
        llVolumeDetect(TRUE); // Starts llVolumeDetect
    }
    collision_start(integer total_number)
    {
 //Your functions will go here, for example the color changing and sound playing
llPlaySound(yoursound, 1);
          llSetColor(<0.6,0.5,0.4>, ALL_SIDES);
    }
}
 llVolumeDetect triggers the collision_start event, so whatever happens in that event will be triggered when an avatar (or object) collides with that object. There are a few things to keep in mind, the first being that the object will turn phantom, so make sure you have another solid prim under that prim if he is walking on it. The other thing to remember is that this function must be applied to the root object.

Hope this helps! Check back tomorrow for the answer to your first question.

1 comments:

Nettrice said...

Thanks! You ROCK...I'll check for the other answer tomorrow. :D

Post a Comment