SLUniverse Forums - View Single Post - Looking for a 'sound on contact' script?
View Single Post
Old 11-02-2009, 11:59 AM   #4 (permalink)
Free Xue
Communist Plot
 
Free Xue's Avatar
Viva La Boxxy!
 
Join Date: May 2009
Location: USA! USA! USA!
Posts: 4,618
My Mood:
SL Join Date: May, 2008
Business: [ Xushi ]
Blog Entries: 1
Quote:
Originally Posted by Fred Rookstown View Post
HINT: collision_start and collision_end
I've found these difficult to use with collision event detection on a floor. Since walking or standing on one behaves almost like a single, constant collision, I often see them triggered only as you hit the floor (collision_start) or leave it (collision_end).

@Vengeance

I've recently done some scripting for collision detection, avatar position and velocity/speed. Here is a snippet of that handiwork. If the sound file you use is a short clip, it should do:

Code:
string mySound = "step.wav"; // sound in prim inventory
vector agentVel; // 'avatar' velocity

default
{
    collision(integer total_number)
    {
        agentVel = llDetectedVel(0); // detect the avatar's velocity

        if( (llFabs(agentVel.x) > 1.5) || (llFabs(agentVel.y) > 1.5) )
        {
            llPlaySound(mySound, 0.5);
            llSleep(0.4);
        }
    }
}
What this does is detect the velocity/speed of an avatar (agent) during a collision event, and if it is equal to or less than 1.5 meters per second in the x or y directions, it plays the sound. 1.5mps is good cut off point I think. Walking velocity is north of 3 in any cardinal direction, and we need to make sure not to trigger the sound when turning (or fidgeting ).

The sleep is in there to cause a break in the multiple collisions occurring. I suggest playing with the duration in the llSleep() function until it fits the sound file's length best. Of course, set mySound to the name of the "walk" sound file that is in the object.
__________________

Boxxy такое интернет-любви!

Last edited by Free Xue; 11-02-2009 at 12:11 PM. Reason: grammar :)
Free Xue is offline   Reply With Quote