From Second Life Wiki
Jump to navigation Jump to search

Push drop-off

As the avatar retreats from the prim that contains the script doing the pushing, the amount of force imparted reduces. I have read some references (on the LSLWiki,) to the idea that the force is f = 1 / r^3 where f is the force applied and and r is the distance (radius) between the prim and the object being pushed. But this doesn't seem to to be valid. I've been using the below code to calculate the push, but it only seems to invert the curve. IE: Standing inside the (phantom) prim at it's center gives no push at all, while being a few meters away gives one whale of a shove.

Here's my code (Abridged for cleaner posting):

    sensor(integer num_detected) {
        for (index = 0; index < num_detected; ++index) {
            // Yes, I know better than to initialize variables inside a loop.  This is demo code ;)
            key avviKey = llDetectedKey(index);
            vector direction = <1.0, 0.0, 0.0> * llGetRot();
            float massComp = llGetObjectMass(avviKey);
            float falloffComp = llPow(llVecDist(llGetPos(), llDetectedPos(index)), 3); // (1 / r^3) * r^3 = 1 / 1 = 1
            llPushObject(avviKey, direction * massComp * falloffComp, ZERO_VECTOR, FALSE);

Like I said, when my avatar is standing in the center of the prim the value of direction * massComp * falloffComp is equal to <0, 0, 0> while further out I am the more of a push I get. What am I missing? Cron Stardust 21:45, 19 April 2007 (PDT)

*makes minor change to your script* try flying when you get pushed, that should eliminate the effects of gravity for your experiment. I'm curious to see how things come out. Also be aware that there is a ceiling on how large a push can be. --Strife Onizuka 23:18, 19 April 2007 (PDT)
Thanks for the edit, I had missed that when I pulled the code from it's environment... I think the solution has been found, through the help of my dad (Vinhold Starbrook). Here is the key part that seems to makes the difference:
            llPushObject(avviKey, direction + direction * massComp * falloffComp, ZERO_VECTOR, FALSE);
Here I add the direction vector into the formula that corrects for distance. That seems to do the job. If I notice any more wierdness, I shall report it. Cron Stardust 21:08, 22 April 2007 (PDT)

Is it possible to retrieve the force of the push inside the object who has been pushed? (i mean, i push an object and iniside of it i make a script to retrieve the force by which it has been pushed).