Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Need help positioning projectile

Dars Coffee
Registered User
Join date: 11 Apr 2005
Posts: 2
08-05-2005 17:08
Alright, I'm still pretty new at this. Most of my scripts come from piecing together and modifying other scripts and even though I understand alot of what's going on I can't figure out what's wrong with this script. The script is attached to a handheld rocket launcher, along with the sound effect and the multi-prim projectile "Rocket." The first script I used spawns the rocket and launches it correctly (straight ahead, that is) but it's always facing straight up.

I got a quick lesson on rotation and came up with the next script, but it always launches the rocket to the east no matter what direction I'm facing and although I can mess with the script to make the rocket face in different directions (it spawns facing up in this script) it always faces the same direction.

What I need the rocket to do is spawn facing straight ahead no matter which direction I'm facing and move where I'm aiming the launcher. Any help would be appreciated.

First section of code 1:
CODE


float SPEED = 10.0;
integer LIFETIME = 100;

float DELAY = 5.0;

vector vel;
vector pos;
rotation rot;

integer have_permissions = FALSE;
integer armed = TRUE;

fire()
{
if (armed)
{
armed = FALSE;
rot = llGetRot();
vel = llRot2Fwd(rot);
pos = llGetPos();
pos = pos + vel;
pos.z += 0.75;


vel = vel * SPEED;


llTriggerSound("Bazooka 1", 4.0);
llRezObject("Rocket", pos, vel, rot, LIFETIME);


llSetTimerEvent(DELAY);
}
}


First section of code 2:
CODE

float SPEED = 10.0;
integer LIFETIME = 100;

float DELAY = 5.0;

vector vel;
vector pos;
rotation rot;
rotation rotb;
vector myrot;
rotation myrotex;

integer have_permissions = FALSE;
integer armed = TRUE;

fire()
{
if (armed)
{
rot = llGetRot();
myrot = llRot2Euler(rot);
myrot.y *= RAD_TO_DEG;
myrot.y *= (myrot.y + 90);
myrot.y *= DEG_TO_RAD;
rot = llEuler2Rot(<myrot.x, myrot.y, myrot.z>);

armed = FALSE;
vel = llRot2Fwd(rotb);
pos = llGetPos();
pos = pos + vel;
pos.z += 0.75;


vel = vel * SPEED;


llTriggerSound("Bazooka 1", 4.0);
llRezObject("Rocket", <pos.x + 5, pos.y, pos.z>, vel, rot, LIFETIME);


llSetTimerEvent(DELAY);
}
}
Catherine Omega
Geometry Ninja
Join date: 10 Jan 2003
Posts: 2,053
08-05-2005 19:54
Yeah, that can be a little tricky to get at first. Here, this code demonstrates how to rez an object aligned to the rotation of the rezzer, at a variable offset.

CODE
default
{
touch_start(integer touched)
{
if (llDetectedKey(0) == llGetOwner())
{
rotation rot = llGetRot();
vector fwd = llRot2Fwd(rot);
vector up = llRot2Up(rot);
vector left = llRot2Left(rot);
vector pos = llGetPos() + (fwd * 2.0); // 2.0 is the distance on the "fwd" axis from the rezzer object.
// add corresponding entries for "up" and "left" here, following the example of the above line for "fwd".
llRezObject("test", pos, <0,0,0> , rot, 0);
}
}
}
_____________________
Need scripting help? Visit the LSL Wiki!
Omega Point - Catherine Omega's Blog