Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

llCollisionSound for Attachments?

Genna Banjo
Registered User
Join date: 22 Feb 2005
Posts: 47
05-08-2005 21:36
Hi. This is my first script and isn't working as I hoped. My goal is to have an object that is attached to me, make a sound when it collides with either another object or the ground. I can make the llcollisionsound but when i attach the object to me, it will not make the sound. Here's the script as it is so far. Any pointers on this?

string impact_sound = "bicyclebell";
float impact_volume = 1.0;

default
{
state_entry()
{
llCollisionSound(impact_sound, impact_volume);
}
}
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-08-2005 22:52
Attachments do not (properly) call collision events themselves - they receive events from the avatar. Supposedly there was a bug with llVolumeDetect that would pass collisions directly, but I consider that a tad dubious.

Alternately, you could do this:

CODE
string impact_sound = "bicyclebell"; // Sound file
float time = 3.0; // Time between collision events
float vel = 5.0; // Minimum velocity needed to trigger a collision sound
float range = 20.0; // Range between lowest and highest collision volume

default
{
state_entry()
{
llMinEventDelay(time);
}

collision_start(integer total_number)
{
float speed = llVecMag(llGetVel());
if(speed > vel)
{
float volume = (speed - vel) / range;

if(volume > 1.0) volume = 1.0;

llCollisionSound(impact_sound, volume);
}
}

land_collision_start(vector pos)
{
float speed = llVecMag(llGetVel());
if(speed > vel)
{
float volume = (speed - vel) / range;

if(volume > 1.0) volume = 1.0;

llCollisionSound(impact_sound, volume);
}
}
}

Since collision events are passed from the avatar itself here, not the attachments, this will be called every time your avatar hits something and moves about. You have been warned.
_____________________
---
Genna Banjo
Registered User
Join date: 22 Feb 2005
Posts: 47
type mismatch
05-09-2005 08:07
Jeffrey and whomever is fascinated with this thread...

that script returns a type mismatch error in the space between the ) and the ; in the first llgetvel line. if i add the line again, the error moves to the second line, same space. any ideas?
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
05-09-2005 08:43
That's becasue llGetVel() returns a vector, not a float. I think the line should read:

float speed = llVecMag(llGetVel());
_____________________
Genna Banjo
Registered User
Join date: 22 Feb 2005
Posts: 47
thanks
05-09-2005 08:52
thanks Jillian.. that fixed the error.

script compiled fine. no sound though. but i'm learning!
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
05-09-2005 12:38
Yeah. Occasionally I slip up. I'll edit the code. ;)
_____________________
---
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
02-27-2006 01:08
This doesn't work at all. I had to completely remove the velocity checks for it to even work detached.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
02-27-2006 07:46
From: Eep Quirk
This doesn't work at all. I had to completely remove the velocity checks for it to even work detached.


It's not ment to be used detached. You would have to remove the velocity checks for it to work detached.
At that point it would just be smarter to set the collision sound llCollisionSound if your going to use it dettached.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Eep Quirk
Absolutely Relative
Join date: 15 Dec 2004
Posts: 1,211
02-27-2006 10:18
Um, duh, Strife, but I'm saying it doesn't work ATTACHED either WITH the velocity checks...