Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Vehicle Projectile Rotational velocity Problem

Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
04-08-2007 10:23
So I've got a projectile that I'm trying to shoot from a vehicle. Now what I need is to have the projectile rezzer take into account the vehicle's velocity when firing so the ship doesn't outrun the round and cause someone to shoot themselves.

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.
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
04-08-2007 12:00
Funny story....my torpedo has suddenly started doing the return junk (goes out until it bleeds off its speed from the rez object and the SetForce takes over and returns right back to me)

Think I might've put an older torpedo in there by accident, which is the script I posted...so I'm going to have to reread that to fix that part again heh.

So if any more competant weapon scripters see the reason for that when they read through it, you can trust that it wasn't doing it previously and is just a temporary mix-up with putting in the wrong script heh.
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
04-10-2007 10:05
I guess I probably need to reword this a little bit.

Basically what I'm hoping someone can assist me in figuring out is a way to take the velocity of the vehicle and add it to the llRezObject's initial velocity and just go straight out from the point of fire. Essentially for the forward velocity of the vehicle to be added to it and the velocity of any other direction to be ignored.

It seems simple, but for some reason I can't get it to work properly.

A simple solution would be to just make the torpedo go faster than the ship ever could and leave it at that, but this is more of a 'for show' weapon than something that I think would be used as a combat device. It's going in one of my physical trek starships, and I want it to have at least a chance of causing the ship it hits to shake from the impact.

I'm thinking you might have to take the vector of the velocity and translate that to a single number to add to the velocity, but I'm just not sure after all the messing around I've done trying to get this to work.
Fenrir Reitveld
Crazy? Don't mind if I do
Join date: 20 Apr 2005
Posts: 459
04-11-2007 10:49
Maybe I am not understanding properly, but why not do this:

CODE

state_entry()
{
float torpedo_speed = 10.0 ;

my_rot = llGetRot();
my_fwd = llRot2Up(my_rot)*2.5;
my_pos = llGetPos() + my_fwd;
vector my_vel = llGetVel() + llRot2Fwd (my_rot) * torpedo_speed;

llRezObject("Torpedo",my_pos, my_vel, my_rot, 0);
llTriggerSound("fmtorp",1);
state default;
}


And then skip all the stuff about calculating velocity in the torpedo code. I assume you want the trajectory of the torpedo to remain constant? ie: Once it fires from the ship, it retains its own initial velocity PLUS the ship's velocity? Then that snippet should do it, it adds the torpedo_speed on top of what's already present with the ship.

You will still have problems with the torpedo and ship ramming if your torpedo's mass makes it slow down and collide with the ship inside the same physics frame.
_____________________
----
----
----
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
04-11-2007 17:01
Well, that's essentially what I had before, and the only problem with it was that it caused the torpedo to strafe since the velocity call uses global variables.

I was able to get it appear to work late last night with:
CODE
state fire
{
state_entry()
{
my_pos = llGetPos();
my_rot = llGetRot();
my_fwd = llRot2Up(my_rot)*0.5;
vector vel = llGetVel();
float speed = llVecMag(vel);
vel = <0,0,speed+10>*my_rot;
llRezObject("Torpedo",my_pos+my_fwd,vel*2,my_rot,0);
llTriggerSound("fmtorp",1);
state default;
}
}


I'm not sure if that's the most elegant solution...but the torpedo appears to move at the same rate away from the ship at 40m/s as it does sitting still and goes straight *shrug* I have a small ricochet problem that happens before it can stop it's forward velocity...but it only happens at really high speeds.