Combat2 introduced the ability for objects to receive damage. In my testing, when firing a damage bullet at four objects with
on_damage
in a way that causes all four to be hit in the same physics frame, all four scripts reported the collision, but only the object created first reported receiving the damage.
In the event of the bullet colliding with both an avatar and an object in the same frame (such as when someone takes cover behind a relatively thin wall), the avatar takes the damage, and that has long been grounds for complaints within the combat community and empowered abuse.
Rider said that the object that receives damage "bubbles up from the physics engine," but so do scripts that fire their
collision_start
events from non-damaging collisions in the same frame. Note that, using the test script below,
collision_start
appears to consistently fire before
on_damage
. If all four objects in that set got the event at the same time, why does the simulator send it only to the oldest object?
I propose that the object (or avatar, or child link) whose center is closest to the bullet's position in the frame before the collision should receive the damage (or prevent it, if the bullet has
REZ_DIE_ON_COLLIDE
). While this wouldn't be as accurate as
a priori
collision detection, it could put to rest the long-standing issue of accusations of "prim shooting", or deliberately shooting at a wall or other object between the shooter and close to the target.
The test script:
default
{
state_entry()
{
llSetText(llGetObjectName(), <1,1,1>, 1);
}
on_damage(integer n)
{
float totalDamage;
while (n--)
{
list damageInfo = llDetectedDamage(n);
totalDamage += llList2Float(damageInfo, 0);
}
llOwnerSay("Took " + (string)llRound(totalDamage) + " damage");
}
collision_start(integer n)
{
llOwnerSay("Collision from " + llDetectedName(0));
}
}
On collision detection: Second Life's physics engine uses the
a posteriori
collision detection model, meaning that, in each physics frame, a physical, moving object "jumps" to the position it should next be in, and any non-phantom objects that it intersects with in that new position is considered a collision. This is in contrast to the
a priori
collision detection model in which the physical object "slides" to its new position in the coming frame, checking for collisions along the way. The trade-off for using the latter method is that while collision detection would be much more consistent and reliable, it has greater performance demand that may not be feasible for a virtual world filled with user-generated content.