Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Particles and bullets

Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
11-25-2005 07:57
I'm pretty new to scripting, so some of these questions are probably easy to answer.

At the moment I'm building an automatic gun turret, not for any particular purpose, just to play around, really. (It only targets people on my land and I switch it off when I log out so it's not giving anyone else any trouble.) The basic idea seems to be working fine. It detects the nearest person, rotates to follow them, issues a warning, changes the colour of a warning light, and, at regular intervals, fires a bullet at them. That all works.

1. The bullet is where I'm having the trouble. I started off with it just having a muzzle flash, which I implemented by having the bullet start an llParticleSystem when it was rezzed at the muzzle of the gun. That worked okay, but the bullet itself was a little unimpressive, so I decided to have it leave a sort of tracer trail behind it, also using llParticleSystem started on_rez, fading from white to black.

This works okay as well (and I quite like the effect) but together they seem to argue. The tracer effect always works, but the muzzle flash doesn't. A lot of the time it doesn't appear at all, but sometimes it does, particularly when you're close to it, which is annoying. Is there a problem with having two separate llParticleSystem calls made by the same object?

2. Is there a way of generating a particle explosion at impact? Whenever I've tried it it seems to last for just an instant before the bullet dies. I assume that llDie is killing the particle system here.

3. My turret seems to have quite a hard time killing me. The velocity is set based on a normalised vector towards the target multiplied by a speed constant. Standing at certain distances the bullet just seems to pass straight through me, but moving backwards or forwards a little means a hit. The problem seems to be less when I reduce the speed of the bullet but of course that means it misses at longer ranges (I'm not up for getting the turret to do ballistic calculations right at the moment, perhaps later). It also doesn't seem to be consistent, in my experience - I played around with the speed constant last night and settled on 35 as giving pretty consistent hits, and when I tried again a couple of hours later I was back to not getting hit. This may just be my imagination though. Does anyone have any ideas here?
Alain Talamasca
Levelheaded Nutcase
Join date: 21 Sep 2005
Posts: 393
11-25-2005 08:09
What is the shape of your bullet?

It has been found by many that the most efficient shape for a bullet in sl is a long thin tube, set to 100% alpha, with a particle tracer

As for impact effects, have you thought of putting something along the line sof "Make particles, sleep for a second or two so particles fully rez, THEN die"?

The reason for the bullet shape is because of the physics engine... it only has ~44 fps, and if you r bullet is going too fast for that speed, it will literally miss you by phasing from in front of you to behind you without ever touching you because those ar ethe locations calculated for those frames.

Ideally, your bullet should be the same length as the distance it will travel in one frame click. this is, of course, not fully practical. Instead, people in the weaponsmithing business have come up with a number of optimized proportions for bullets. You will need to talk to them about that, since I am not a weaponsmith... just ask anyone.

I am an architect, a sculptor and a jeweler.
_____________________
Alain Talamasca,
Ophidian Artisans - Fine Art for your Person, Home, and Business.
Pando (105, 79, 99)
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
11-25-2005 08:16
Ah, I thought it might be something like that. At the moment, the bullet is a slightly elongated spheroid, but not that elongated. I'll try stretching it further.

Pity that it will have to be made transparent - the black core at the centre of the white flare looks quite good, I think. But a sort of spear would look silly. Oh well.

edit: if the maximum range is 96m and frame rate is 44ish, it sounds like around 2.5m would be a safe length.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
11-25-2005 08:22
As for the contact explosion... I was re-reading the wiki just now and for llSetDamage it does say
From: someone
Sets the amount of damage that will be done to an avatar that the scripted object collides with. The scripted object will die (be deleted) immediately on colliding and no event handlers will be executed first.

which may be my problem. It can't do damage until it collides, and when it collides it's not executing the explosion because no event handlers are being executed. (Probably the "instant" explosion was just the usual thing that flashes up when objects collide, not my particles.)

Perhaps the first bullet could be no-damage, but rez a second bullet just behind it, start an explosion and die, and the second bullet would do the damage? Hmm.

Thanks for the advice btw!
Les White
sombish
Join date: 7 Oct 2004
Posts: 163
11-25-2005 14:30
2. a prim can only run one particle system at a time as far as i know. Make sure you end one system before starting the next, or, use two prims for your bullet. Maybe make the flash system come from the gun, trail from the bullet.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
11-25-2005 14:37
I did originally think of having the flash generated by the gun, but I couldn't work out how to have a particle system explosion start at an offset from the centre....
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
11-25-2005 15:54
From: Ordinal Malaprop
I did originally think of having the flash generated by the gun, but I couldn't work out how to have a particle system explosion start at an offset from the centre....
Add a prim to the end of the barrel to generate the particles. You can make it a transparent blob, or make it part of the barrel like muzzle brake or flash suppressor.

Which would be nicely ironic. :)
Lex Neva
wears dorky glasses
Join date: 27 Nov 2004
Posts: 1,361
11-26-2005 10:12
From: Ordinal Malaprop
which may be my problem. It can't do damage until it collides, and when it collides it's not executing the explosion because no event handlers are being executed. (Probably the "instant" explosion was just the usual thing that flashes up when objects collide, not my particles.)


Ah, but you can change those particles. Check out llCollisionSprite(). It may not be ideal, but it may do what you want.