Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Collision Detection, Interacting Objects

Yonke Ming
Fat Laughing Hyena
Join date: 18 Jun 2005
Posts: 16
06-27-2005 13:17
Okay, here is something that I want to do.

First off, collision detection. Basically, I wanted the object to do something if it touches your avatar/ vice versa.

----Case----
Object is a Basketball.
The Basketball hits your Avatar.
The Basketball says "Sorry!"
-----------

Now, I want objects to also interact each other. In a complex example....

----Case----
Object is a box.
The Avatar has a sword.
It hits the object WITH the sword.
The box says "Ouch!".
The sword says "Haha!".
---------------

Now if you can help, I would appreciate it.
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
06-27-2005 13:39
Try looking over this page:
http://secondlife.com/badgeo/wakka.php?wakka=collisions
and the pages it links to.
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
06-27-2005 13:51
Here are some example scripts to get you going.
For your basketball:
CODE

default {
collision_start(integer numColliders) {
integer i;
for (i = 0; i < numColliders; ++i) { // For every collider...
if (llDetectedType(i) & AGENT) { // If its an AGENT (avatar)
llSay(0, "Sorry!");
}
}
}
}


Because attachments are phantom (non-collidable objects), they will not trigger a collision event in the hit object when they appear to hit the object. Instead, your sword should shout a message on a private chat channel when it detects that it interpenitrates the object. The box should then listen on that channel, and react to the message.

For the sword:
CODE

integer COLLISION_CHANNEL = 19484;
default {
state_entry() {
llVolumeDetect(TRUE); // So the attachment can detect collision with the box.
}
collision_start(integer totalNumber) {
integer i;
for (i = 0; i < totalNumber; ++i) {
llShout(COLLISION_CHANNEL, (string)llDetectedKey(i));
}
}
}


For the box:
CODE

integer COLLISION_CHANNEL = 19484;
default {
on_rez(integer totalNum) {
llResetScript();
}
state_entry() {
llListen(COLLISION_CHANNEL, "", NULL_KEY, (string) llGetKey());
}
listen(integer channel, string name, key id, string message) {
llSay(0, "Ouch!");
}
}


You might have trouble with the sword. Animations are client side effects, so when you play an animation of your avatar swinging the sword at something, the "actual" sword might not be how it appears on your client. Im not exactly sure how llVolumeDetect works when in an attachment (Ive forgotten the results of my past tests on it) so you might need to use a sensor instead.
==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm