Don't click here unless you want to be banned.

LSL Wiki : Collisions

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are


In SL, a collision occurs when two objects make contact (impact, collide) in-world. Phantom objects do not cause collision events unless llVolumeDetect is used, except in the case of land collisions.

A script can have a stack/heap collision.

Attachments will not trigger collision events if the object itself collides with something else. However, if the avatar collides with the object, the collision event is triggered.

Note: collisons are not "touches", which is when a user clicks ("touches") on the object with their mouse cursor.

Function Purpose
llCollisionFilter Limits collisions to a specific name or key, so only collisions with a certain object(s) or agent(s) will trigger them.
llCollisionSound Replaces or disables the sound the object makes when something collides with it.
llCollisionSprite Replaces or disables the particles the object emits when something collides with it.
llDetectedGrab Returns the direction the detected object is being dragged in.
llDetectedGroup Returns TRUE if the detected agent/object is in the same active user group.
llDetectedKey Returns the key of the detected agent/object.
llDetectedLinkNumber Returns the link number that triggered the collison/touch event.
llDetectedName Returns the name of the detected agent/object.
llDetectedOwner Returns the key of the detected agent/object's owner.
llDetectedPos Returns the position of the detected agent/object.
llDetectedRot Returns the rotation of the detected agent/object.
llDetectedType Returns the detected object type (AGENT, ACTIVE, PASSIVE, SCRIPTED).
llDetectedVel Returns the velocity of the detected agent/object.
llPassCollisions In a linked object, passes collison events from a child prim containing a collision event to the parent.
llVolumeDetect Turns the object phantom and triggers collision_start and collision_end events when an agent/object intersects it.

Event Triggered
collision while agent/object is colliding with the object containing the script
collision_start when agent/object starts colliding with with the object containing the script
collision_end when agent/object stops colliding with with the object containing the script
land_collision while the object containing the script is colliding with the ground
land_collision_start when the object containing the script starts colliding with the ground
land_collision_end when the object containing the script stops colliding with the ground

Example Script:

//By James Benedek
//Collision Detection
        collision(integer num_detected)
         if (llDetectedType(0) & AGENT)
         llSay(0,"I Collided with an Avatar!");
         if (llDetectedType(0) & ACTIVE)
         llSay(0,"I Collided with a Physical Object!");
         if (llDetectedType(0) & SCRIPTED)
         llSay(0,"I Collided with a Scripted Object!");
        if (llDetectedType(0) & PASSIVE)
         llSay(0,"I Collided with a Object!");
        land_collision(vector pos)
        llSay(0,"I Collided With Land!");


Functions | Events | Detection | Physics
Comments [Hide comments/form]
Has anyone tested the behavior of functions heavily dependent on the timing of each event, like llDetectedVel? If I want to get the velocity of my falling object an instant before the collision happens, do I call llGetVel in the collision_start event? Can I determine the time it took for two objects to collide by calling llResetTime in the collision_start event and llGetTime in the collision_end event?

Im trying to determine the force exerted upon an object due to a collision, and all formulas point to force = change in velocity / time. How can I measure the two required variables using the events provided? Is it possible?
-- ChristopherOmega (2005-07-12 11:47:24)
Use two objects with collision events.
-- DolusNaumova (2005-09-30 11:58:13)
All i would do is the something close to the following:
vector lastvel;
        llSetText("Force: "+(string)(llGetVel()-lastvel),<1,1,1>,1);
-- SchitsoMonkey (2005-10-07 23:02:37)
I seems the only way to detect collisions with non-physical objects is with a non-phantom physical object. A VolumeDetect object, physical or not won't.
-- RalphDoctorow (2006-01-07 16:27:04)
force = change/time
So, if you have a physical object being hit, you need a start velocity. Assuming it's at rest, you should be able to assume 0, but you can always check on state_entry or on_rez with llGetVel();. Store it in a variable, we'll call it lastvel like Monkey did. Then:
llSay(0, "Force: " +(string)(llGetVel() - lastvel);
Monkey's idea, with set text, is a good idea though, if you won't always be in range of your object.
If you're trying to measure the force on a non physical object, since it won't have a velocity, I dunno how you'd go about that.
-- EagleBird (2006-08-17 06:30:58)
Attach a comment to this page: