Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

problem with a disc throwing gun

DirkDougler Duncker
Registered User
Join date: 17 Aug 2006
Posts: 6
08-28-2006 21:58
Hi Everybody,

I am trying to make a disc throwing "gun" reminscent of the movie Tron. With the gun looking like a disc, and really just firing a bullet identical to the disc in hand.

I attempted to drop the code for popgun with a few modifications to allow changing the disc color into the disc in hand which actually never goes anywhere. I then created several different colored discs to put in the disc gun's inventory and scripted them with the ball script as well as all sounds and textures.

My problem is when I fire the weapon, the disc rezzes where it should but never moves. It just floats in front of the mouseview. Could this have to do with the mass of the object?


To anybody that replies thank you in advance.

--Doug

This is the disc gun code:
CODE

//
// Popgun
//
// This script is a basic gun- it waits for a mouseclick in mouselook and
// then fires a bullet in the direction the user is facing.
// It also animates the avatar holding it, to create a convining hold and
// firing look for the gun.
//
// This script can be used as a good basis for other weapons.
//

float SPEED = 75.0; // Speed of arrow in meters/sec
integer LIFETIME = 7; // How many seconds will bullets live
// before deleting themselves
float DELAY = 0.2; // Delay between shots to impose

vector vel; // Used to store velocity of arrow to be shot
vector pos; // Used to store position of arrow to be shot
rotation rot; // Used to store rotation of arrow to be shot

integer have_permissions = FALSE; // Indicates whether wearer has yet given permission
// to take over their controls and animation.

integer armed = TRUE; // Used to impose a short delay between firings

string instruction_held_1 = "Use Mouselook (press 'M') to throw a disc.";
string instruction_held_2 = "Choose 'Detach' from my menu to disc away. Change color of discs by saying --disc red-- or other colors";
// Echoed to wearer when they are holding the bow
string instruction_not_held =
"Choose 'Acquire->attach->left hand' from my menu to use disc.";
// Echoed to toucher if not worn


fire()
{
//
// This subroutine creates and fires an arrow
//
if (armed)
{
//
// Actually fires the arrow
//
armed = FALSE;
rot = llGetRot(); // Get current avatar mouselook direction
vel = llRot2Fwd(rot); // Convert rotation to a direction vector
pos = llGetPos(); // Get position of avatar to create arrow
pos = pos + vel; // Create arrow slightly in direction of travel
pos.z += 0.75; // Correct creation point upward to eye point
// from hips, so that in mouselook we see arrow
// travelling away from the camera.
vel = vel * SPEED; // Multiply normalized vector by speed

//llStartAnimation("shoot_R_handgun"); // Trigger the bow release animation
llTriggerSound("shoot", 1.0); // Make the sound of the arrow being shot

/////////////////////////Red//////////////////////////////
if (llGetColor(ALL_SIDES) == <1.0,0.0,0.0>)
{
llRezObject("red disc", pos, vel, rot, LIFETIME);
}
/////////////////////////Green//////////////////////////////
if (llGetColor(ALL_SIDES) == <0.0,1.0,0.0>)
{
llRezObject("green disc", pos, vel, rot, LIFETIME);
}
/////////////////////////Blue//////////////////////////////
if (llGetColor(ALL_SIDES) == <0.0,0.0,1.0>)
{
llRezObject("blue disc", pos, vel, rot, LIFETIME);
}
/////////////////////////Yellow//////////////////////////////
if (llGetColor(ALL_SIDES) == <1.0,1.0,0.0>)
{
llRezObject("yellow disc", pos, vel, rot, LIFETIME);
}
/////////////////////////Black//////////////////////////////
if (llGetColor(ALL_SIDES) == <0.0,0.0,0.0>)
{
llRezObject("black disc", pos, vel, rot, LIFETIME);
}


// Create the actual arrow from object
// inventory, and set its position, velocity,
// and rotation. Pass a parameter to it to
// tell it how long to live.

llSetTimerEvent(DELAY); // Wait until can fire again
}
}

default
{
state_entry()
//
// This routine is called whenever the script is edited and restarted. So if you
// are editing the bow while wearing it, this code will re-request permissions
// to animate and capture controls.
//
{
if (!have_permissions)
{
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
}
on_rez(integer param)
{
//
// Called when the gun is created from inventory.
//
llPreloadSound("shoot"); // Preload shooting sound so you hear it
}

run_time_permissions(integer permissions)
{
//
// This routine is called when the user accepts the permissions request
// (sometimes this is automatic)
// so on receiving permissions, start animation and take controls.
//
if (permissions == PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS)
{
if (!have_permissions)
{
llWhisper(0, instruction_held_1);
llWhisper(0, instruction_held_2);
}
llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE);
llStartAnimation("hold_R_handgun");
have_permissions = TRUE;
}
}

attach(key attachedAgent)
{
//
// If attached/detached from agent, change behavior
//
if (attachedAgent != NULL_KEY)
{
// Bow has been attached or rezzed from inventory, so
// ask for needed permissions.
llRequestPermissions(llGetOwner(),
PERMISSION_TRIGGER_ANIMATION| PERMISSION_TAKE_CONTROLS);
}
else
{
// Bow has been detached from avatar, so stop animation and release controls
if (have_permissions)
{
llStopAnimation("hold_R_handgun");
llStopAnimation("aim_R_handgun");
llReleaseControls();
llSetRot(<0,0,0,1>);
have_permissions = FALSE;
}
}
}

control(key name, integer levels, integer edges)
{
// This function is called when the mouse button or other controls
// are pressed, and the controls are being captured.
//
// Note the logical AND (single &) used - the levels and edges
// variables passed in are bitmasks, and must be checked with
// logical compare.
//
// Checking for both edge and level means that the button has just
// been pushed down, which is when we want to fire the arrow!
//
if ( ((edges & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON)
&&((levels & CONTROL_ML_LBUTTON) == CONTROL_ML_LBUTTON) )
{
// If left mousebutton is pressed, fire arrow
fire();
}
}

touch_end(integer num)
{
// If touched, remind user how to enter mouselook and shoot
if (have_permissions)
{
llWhisper(0, instruction_held_1);
llWhisper(0, instruction_held_2);
}
else
{
llWhisper(0, instruction_not_held);
}
}

timer()
{
// After timer expires, allow user to shoot bow again
llSetTimerEvent(0.0);
armed = TRUE;
}

}


And this is the "bullet" code
CODE

//
// Popgun Bullet
//
// Becomes non-physical on impact, makes a little particle system, then fades away.
//

integer fade = FALSE;
float alpha = 1.0;

splat()
{
llSetStatus(STATUS_PHANTOM, TRUE);
vector pos = llGetPos();
llMoveToTarget(pos, 0.3); // Move to where we hit smoothly
llTriggerSound("splat4", 1.0);
llMakeFountain(50, 0.3, 2.0, 4.0, 0.5*PI,
FALSE, "drop", <0,0,0>, 0.0);
fade = TRUE;
llSetTimerEvent(0.1);
}
default
{
state_entry()
{
llSetStatus( STATUS_DIE_AT_EDGE, TRUE);
}

on_rez(integer delay)
{
llSetBuoyancy(1.0); // Make bullet float and not fall
llCollisionSound("", 1.0); // Disable collision sounds

if (delay > 0)
{
llSetTimerEvent((float)delay); // Time until shot deletes itself
}
}

collision_start(integer total_number)
{
splat(); // When we hit something, go spat!
}
land_collision_start(vector pos)
{
splat(); // When we hit the ground, go splat!
}

timer()
{
if (!fade)
{
llDie();
}
else
{
// Slowly turn transparent, then go away.
llSetAlpha(alpha, -1);
alpha = alpha * 0.95;
if (alpha < 0.1)
{
llDie();
}
}
}
}
nand Nerd
Flexi Fanatic
Join date: 4 Oct 2005
Posts: 427
08-28-2006 23:22
First thing I would check is that you are turning physics on (for the bullet disc) before you take it into your inventory. Then you drop that into the gun's contents.

There is certainly no code in the bullet to turn physics on ( would look like: llSetStatus(STATUS_PHYSICS, TRUE); ) however even adding this line to your code probably wouldn't help as you'll find that the gun is scripted to rez the bullet with a velocity and the bullet does not do anything to propel itself.
_____________________
www.nandnerd.info
http://ordinalmalaprop.com/forum - Ordinal Malaprop's Scripting Forum
DirkDougler Duncker
Registered User
Join date: 17 Aug 2006
Posts: 6
Thank you so much!!
08-29-2006 01:24
IT WORKS!! That was it... physics was turned off.

I just started in this game like a week ago. I am learning on the fly how to script. I was tearing out hair with this one.

Thanks for your help Nand

--Doug