Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Metal Baseball Bat Malfunction

Jessica Ingmann
Lv. 23 Batcase
Join date: 8 Oct 2005
Posts: 35
10-10-2005 21:51
CODE
vector velocity;
float DELAY = 0.2;
float hitpower = 10;
float alpha = 1.00;

integer have_permissions = FALSE;
integer armed = TRUE;

swing()
{
if (armed)
{
armed = FALSE;
llStartAnimation("throw_r");
llSetTimerEvent(DELAY);
}
}

hit()
{
vector vel = llGetVel() * hitpower;
llPushObject(llDetectedKey(0), vel, ZERO_VECTOR, FALSE);
llSetForce(<0,0,0>, TRUE);
llSetForce(<0,0,0>, TRUE);
}


default
{
state_entry()
{
llCollisionFilter("", NULL_KEY, TRUE);
}

attach(key attached)
{
if (!have_permissions)
{
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
else
{
}
}
run_time_permissions(integer permissions)
{
if (permissions == PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS)
{
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("hold_throw_R");
have_permissions = TRUE;
}
}

attach(key attachedAgent)
{
if (attachedAgent != NULL_KEY)
{
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
else
{
if (have_permissions)
{
llStopAnimation("hold_throw_R");
llStopAnimation("throw_R");
llReleaseControls();
have_permissions = FALSE;
}
}
}
control(key name, integer levels, integer edges)
{
if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
&&((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
{
swing();
}
}

collision_start(integer total_number)
{
hit();
}
touch_start(integer total_number)
{
hit();
}

timer()
{
llSetTimerEvent(0.0);
armed = TRUE;
}
}


I've got a baseball bat that isn't working. You fix it, you get a free copy and five for your friends.(Seeing as I'm broke as Hell.) And. . .I guess anyone else who reads this now would have working code for one, too. But I digress.
Thanks in advance for anything you might do. And set, the "Physical" checkbox is checked.
Fenrir Reitveld
Crazy? Don't mind if I do
Join date: 20 Apr 2005
Posts: 459
10-10-2005 23:09
AFAIK, all attachments act phantom when they are attached to you. Having physics turned on won't do a thing.

I'm not sure how/if collision events are passed to attachments, as it's not something I've ever played with.
Jessica Ingmann
Lv. 23 Batcase
Join date: 8 Oct 2005
Posts: 35
10-11-2005 00:35
Well, a friend of a friend suggested projectiles -- invisible, small ones that can be collided with. It works, but if there's a better way, I'd love to hear it.
Fenrir Reitveld
Crazy? Don't mind if I do
Join date: 20 Apr 2005
Posts: 459
10-11-2005 01:32
Teehee. Yeah, that works... Or, you could have a single sensor event fire, that searches for your baseball object and then apply impulse to it based on the avatar's rotation. Use a small arc, like maybe PI/4. (Not sure where the arc will orginate from however -- avatar's rotation, or attachments.)