Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Homing Missile Script

Tyreal Overdrive
Registered User
Join date: 16 Oct 2005
Posts: 4
07-30-2007 08:48
I'm looking for a basic homing missile or projectile script. I have worked with gun scripts in the past and have never gone about doing this one it would be greatly appreciated if I could se at least a few lines of code to know what to do.
Lily Cicerone
Registered User
Join date: 25 Jan 2007
Posts: 30
07-30-2007 09:30
A basic homing missile script should not be too difficult although I can see a lot of little problems you are going to have to fix. I assume you will have a specific target in mind, so you will probably want to rez the missile, send it its target and some trigger to activate. When activated, it will probably need to use a sensor to find the position of its target, which you can then use in llMoveToTarget to send the missile in pursuit. Simple enough..

Written this way, the missile will strike the original position of its target, but if the target happens to move between the time the missile rezzed and hit the target's original location, the target may have moved. For this reason, you may need to set a timer for the missile to rescan every half second or so for its target's current position, possibly more frequently as it gets closer. A collision event will trigger detonation, so if it misses it will just rescan and launch at the target again.

Another problem is that using llMoveToTarget will send the missile directly at the target's position no matter what is in the way. The more you try to make the missile avoid obstacles the more complicated the script is going to become but I imagine with sensors and a lot of time you could make it fairly precise. A simple solution if you plan to use the missile out of doors only (and this is fairly normal practice with homing missiles anyway I believe) is have the missile fly into the air before activating llMoveToTarget toward the person you are aiming at. By descending from the sky, the missile is at least less likely to hit small obstacles on the ground.

Finally, one issue I have not addressed is that llMoveToTarget moves the object but does not point it. You're going to need to play around with rotations for this, and that's a lot of math that isn't particularly my strong point but I am sure you will be able to figure it out.
Scott Tureaud
market base?
Join date: 7 Jun 2007
Posts: 224
07-30-2007 14:22
llRotlookAt. and every so often apply the force in the direction of that it's looking.

obviously not the most efficient way to hit your target, or most efficient script. but it'd look very stylized.