Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Precision aim with llSensor in mouselook

Chairman Singer
Registered User
Join date: 27 Sep 2005
Posts: 4
09-27-2006 16:40
wow what a great thread!
silly question from a new comer to scripting...

In thhe conext of a gun like weapon
You put the sensor on the gun and pass the target to the bullet right?
(i.e. should the bullet get it's own sensor?)
Seifert Surface
Mathematician
Join date: 14 Jun 2005
Posts: 912
09-27-2006 17:05
From: Gerami Fizz
That said, I'm not particularly familiar with how non-root based sensors work when in a HUD, but I'd love to find out. If not the hips, what position do they use as a point of origin?
I'm not entirely sure, but I'd be very surprised if non-root prims in attachments didn't report the ceneter of the avatar again. The physics engine on the server currently has no knowledge of the positions of attachments.
_____________________
-Seifert Surface
2G!tGLf 2nLt9cG
Gerami Fizz
That Guy
Join date: 15 Jun 2005
Posts: 88
09-27-2006 19:51
Chairman: FYI this system I'm designing doesn't use bullets at all. That's part of the beauty of it. Instead, the sensor in the gun detects whether or not a bullet would have hit the target, and does some other proprietary magic pertaining to damage and such.

Seifert: I remember reading something about how sensors in non-root prims in attachments will detect the avatar they're attached to. It's a start!
Chairman Singer
Registered User
Join date: 27 Sep 2005
Posts: 4
09-28-2006 12:25
From: Gerami Fizz
Chairman: FYI this system I'm designing doesn't use bullets at all. That's part of the beauty of it. Instead, the sensor in the gun detects whether or not a bullet would have hit the target, and does some other proprietary magic pertaining to damage and such.


Sounds pretty cool!
When it's done let me know where it's for sale :)

For my low level experience though I would imagine a gun sensor that passes target info to a "bullet" would be more elegant than a bullet with it's own sensor.
(though that wouldn't be the case if you were designing a cruise missile) :)
Gerami Fizz
That Guy
Join date: 15 Jun 2005
Posts: 88
09-28-2006 12:32
In most cases, you don't need to pass a target to the bullet at all... just point it forward relative to the launcher/avatar and apply some force to it, and simple physics takes care of the rest.

Of course, it can be a lot more complicated than that, but telling a bullet where it's going when it's going there anyway is kind of moot.

Now, if you wanted the bullet to tell the gun its position -after- it hits... that's a whole other story. :-)
Rich Cordeaux
Registered User
Join date: 8 May 2006
Posts: 26
10-04-2006 13:09
Personally, I'm using sensors for short-range weapons (melee weapons, flamethrowers, and the like), and bullets for medium- and long-range weapons. So I've made the sensor cone fairly large but the distance short (say, 2 meters).

As for the guns which fire bullets, the bullets don't work well at close range, since they tend to hit nearby targets before their on_rez event can set up the bullet properties, and no, it can't be done in state_entry instead due to validation of the bullet requiring the key of the bullet.

Hmm, actually, I have an idea. Perhaps I can make the bullet recognize if its properties haven't been set yet upon collision, and if so, send a short-range attack message instead. I think this'll be a little tricky - events can apparently queue up while other events are being executed, so I'm relying on setting a variable to 0 in state_entry, setting it to 1 in on_rez, and setting it to 2 in the timer event, with llSetTimerEvent(0.1) being called after on_rez has set the bullet properties. The collision events will check to see what the variable is, and for now just tell me what it is if it's not 2. I'm expecting it to be 2 at long range and 1 at all other ranges. Here's my reasoning:

I'm theorizing that (a) events in one script can NOT interrupt other events in the same script, and (b) events can be queued during other events, and (c) on_rez should be queued first so nothing else executes before it

My reasoning for (a) is that nothing would work reliably at all if it wasn't true.
My reasoning for (b) is that I have witnessed a timer() event happening after llSetTimerEvent(0.0) has been called, and the only sane reason that could happen would be if (b) was true and was the cause. Here's almost-LSL pseudocode similar to the test script I made to check this:

CODE

integer timerEnabled;
default {
state_entry() {
timerEnabled=1;
llSetTimerEvent(0.1);
}
collision_start(integer num_detected) {
//we are doing stuff here;
//timer elapsed, timer() event is queued as a result;
//we are doing some more stuff;
timerEnabled=0;
llSetTimerEvent(0.0);
}
timer() {
if (timerEnabled==0) {
llOwnerSay("zounds!");
}
}
}


The "zounds!" message was going off. (I don't remember exactly what event - it might not have been collision_start - I was seeing this in. I also don't remember where I put the test script. :P)

I don't have any evidence for (c), but that why I'm testing this to see what results I get. If I see 0s, then I'll know that collision events can be queued before on_rez.
Llauren Mandelbrot
Twenty-Four Weeks Old.
Join date: 26 Apr 2006
Posts: 665
Event Queue
10-06-2006 08:02
From: Rich Cordeaux
I'm theorizing that (a) events in one script can NOT interrupt other events in the same script, and (b) events can be queued during other events, and (c) on_rez should be queued first so nothing else executes before it
Confirmed, except I think that state_entry gets called first, if this script has never been in-world before.
Rich Cordeaux
Registered User
Join date: 8 May 2006
Posts: 26
10-07-2006 21:08
Yep. In my case, state_entry was always being run when the script was first put into the bullet, and the code in the on_rez event was set up to only run if the parameter was non-zero. Also, IIRC on_rez won't be run when the script is first placed into an in-world object (if I'm wrong about that, then it won't have a non-zero parameter, so it wouldn't trigger my code in on_rez anyways).

My testing did confirm (c), so I was able to make my bullets detect if they had collided before having been initialized, and to send the short-range attack message when that happens.
1 2 3