Monday, February 06, 2006

Not as hard as I thought

Well, colour me an embarrassed shade of mauve - after lots of faffing about with llSetTorque et cie, I find that llRotLookAt does work with physical objects, it's just that you need rather inflated parameters to get it to do anything.

If we declare

float strength;
float damping;

at the top of the script, and set those variables to be

strength = llGetMass()*3;
damping = strength/3;

in state_entry(), things work out quite well if we just add the instruction to rotate to set_engine, which now looks like this:

set_engine(vector dir)
vector vel = llGetVel();
vector drag = vel / gMaxSpeed;
rotation rot = llGetRot();
llRotLookAt(rot * llRotBetween(<1,0,0> * rot, vel),
strength, damping);

llSetForce((dir - drag) * gAcceln * gTimer, FALSE);
gFuel -= gTimer;
if (gFuel <= 0) explode();

And thus we have a rocket that now moves to point in its direction of travel, calculating the rotation between its forward axis and the velocity using llRotBetween, multiplying that by its actual rotation and then turning there. Don't ask me how that works. I really don't understand rotations very well, still, I'm afraid. I got a lot of that from the wiki page about llLookAt.

Firing and ejecting

I also added a longer detection spike, to let the maximum speed go up a bit, and added a little more flash to the launcher - now, once you run out of ammunition, the Harlequin ejects the empty cartridge (which bounces about for a bit on the ground and emits smoke) and you go through a reloading animation. I think it looks rather good, personally.

What remains is to give the rockets a slight heat-seeking element, pointing them a little towards the nearest avatar. This will probably just make them miss, but should help at long ranges. Not that I can see anything past 96m in any case.


Post a Comment

<< Home