Jump to content

Raycast airpistol


Quistess Alpha
 Share

You are about to reply to a thread that has been inactive for 948 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

This is. . . way too much fun not to share. Drop this in an attachment, then touch a standard-issue unscripted 0.5 by 0.5 physical box prim while in mouse-look on push-enabled land:

// Basic airpistol script by Quistess Alpha, sept-09-2021
// no animation or sound effects included.

// configuration options:
float gPower = 40.0;
float gPower_rot = 10.0;

//
// script-managed variables:
//

integer gPermsWanted;

default
{
    state_entry()
    {   gPermsWanted = PERMISSION_TAKE_CONTROLS|PERMISSION_TRIGGER_ANIMATION|PERMISSION_TRACK_CAMERA;
        llRequestPermissions(llGetOwner(),gPermsWanted);
    }
    attach(key ID)
    {   if(ID)
        {   llRequestPermissions(ID,gPermsWanted);
        }
    }
    run_time_permissions(integer perms)
    {   if(perms==gPermsWanted)
        {   state running;
        }
    }
}
state running
{
    state_entry()
    {   llTakeControls(CONTROL_ML_LBUTTON,TRUE,TRUE);
    }
    changed(integer c)
    {   if(c&CHANGED_OWNER) llResetScript();
    }
    attach(key ID)
    {   if(ID) // was attached (not detached)
        {   state default;
        }
    }
    control(key ID, integer level, integer edge)
    {
        if(level&edge)
        {   // assume mousebutton because only control taken
            vector S = llGetCameraPos();
            vector F = S+128*llRot2Fwd(llGetCameraRot());
            list ray = llCastRay(S,F,[RC_DATA_FLAGS,RC_GET_ROOT_KEY|RC_GET_NORMAL]);
            llOwnerSay(llList2CSV(ray));
            key ID = llList2Key(ray,0);
            vector positionHit = llList2Vector(ray,1);
            vector posObjCenter = llList2Vector(llGetObjectDetails(ID,[OBJECT_POS]),0);
            vector normal = llList2Vector(ray,2);
            vector posDiff = posObjCenter-llGetPos();
            
            vector rotImpulse = llRot2Euler(llRotBetween(normal,positionHit-posObjCenter));
            
            float powerFactor = llPow(posDiff*posDiff,1.5); // distance cubed.
            
            llPushObject(ID,<0,0,0>,rotImpulse*gPower_rot*powerFactor,FALSE);
            llSleep(0.022); // that I have to split these in two is a bug. . .
            llPushObject(ID,llVecNorm(posDiff)*gPower*powerFactor,<0,0,0>,FALSE);

        }
    }
}

Now, if only I knew why llPushObject() is acting funny when I specify both a translation and a rotation. . .

Edited by Quistess Alpha
  • Like 2
  • Thanks 1
Link to comment
Share on other sites

36 minutes ago, Emma Krokus said:

[05:01]  Object: Script trying to take controls from owner but PERMISSION_TAKE_CONTROLS permission not set!

Fixed. (looped back to state default from state running on attach) not in the most efficient fashion, but shouldn't bring up the error at least.

  • Like 1
Link to comment
Share on other sites

4 hours ago, Quistess Alpha said:

Fixed. (looped back to state default from state running on attach) not in the most efficient fashion, but shouldn't bring up the error at least.

Got a script error here:

attach(key ID)

{

     if(ID) // was attached (not detached)

     {

          state default

     }

}

So added ; after state default which made that go away...

Probably the wrong thing though. Not getting the permissions' error again though. When I click the unscripted prim in Mouselook (I have to enable it, it doesn't automatically happen), I get this message:

[10:32]  Object: 1289bcfb-144e-5354-501b-a5847249993b, <32.921162, 87.710396, 1856.039429>, <0.000000, 1.000000, 0.000000>, 1

Sings: "Girls just wanna have fun"

Link to comment
Share on other sites

1 hour ago, Emma Krokus said:

I get this message:

[10:32]  Object: 1289bcfb-144e-5354-501b-a5847249993b, <32.921162, 87.710396, 1856.039429>, <0.000000, 1.000000, 0.000000>, 1

Yeah, I was too lazy to  disable debug owner-say. Did your physical prim move though? were you on push-enabled land?

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 948 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...