The firing/aiming/orientation and all that is fine. It comes right out the torpedo launcher and heads straight out from the fire point. The problem is that when I try to account for the vehicle's speed and add the velocity to the projectile, it causes the round to curve based on the other floats of the vector.
I've tried various ways to get around this by using the .x of the vector, but it just doesn't seem to work.
The rez prim is a child prim with a rotation of 0,90,270, and the round is configured so that this rotation is what it needs.
Here is the launcher script:
CODE
vector my_pos;
rotation my_rot;
vector my_fwd;
default
{
state_entry()
{
llPreloadSound("fmtorp");
}
link_message(integer send,integer num, string msg, key id)
{
if (msg == "torp")
{
state fire;
}
}
}
state fire
{
state_entry()
{
my_pos = llGetPos();
my_rot = llGetRot();
my_fwd = llRot2Up(my_rot)*2.5;
vector vel = llGetVel();
//vector offset = llRot2Fwd(my_rot)*0.5;
llRezObject("Torpedo",my_pos+my_fwd,(my_fwd*20)+<0,0,0>,my_rot,0);
llTriggerSound("fmtorp",1);
state default;
}
}
and here is the round script:
CODE
float hitpower = 999999;
float speed = 2;
vector vel;
setVel(vector newVel, integer localAxis)
{
vector curVel = llGetVel();
if(localAxis)
{
rotation rot = llGetRot();
curVel /= rot; // Un-rotate curVel.
}
newVel += curVel;
newVel *= llGetMass();
llSetForce(newVel,localAxis);
}
default
{
state_entry()
{
llSetBuoyancy(1.0);
}
collision_start(integer total_number)
{
llSetStatus(STATUS_PHYSICS,FALSE);
llPushObject(llDetectedKey(0), vel, ZERO_VECTOR, FALSE);
llTriggerSound("exp2",1);
llRezObject("smoker", llGetPos() + <0,0,0>, ZERO_VECTOR, ZERO_ROTATION, 1);
llDie();
}
on_rez(integer par)
{
vel = llGetVel();
setVel((<0,0,vel.z>+<0,0,20>),TRUE);
llSetStatus(STATUS_PHANTOM,FALSE);
vel = (llGetVel()*100) * hitpower;
//llApplyImpulse(new,FALSE);
}
}
Now I'm no weapon's coder, but I think I have this set well....the torpedo is phantom so it will get a little bit away from the ship to avoid collisions, but I really need it to vary the initial speed so that when I'm going more than 10m/s it will get away from the ship.
While messing with it I've had all kinds of wierd stuff happen from 'returning' as in it comes right back at me, to just stopping.
Any help is appreciated. =)
Edit: changed "newVel -= curVel;" to "newVel += curVel;" to fix boomer-rang effect.