Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Making a projectile stick to a target.

Ephyu Reino
Registered User
Join date: 18 Jan 2007
Posts: 16
01-18-2007 13:56
Thinking of making an object that acts, at least a little, like the Plasma grenades in Halo, except to be fired from a gun.

I feel I need to add this, because it's been brought up in nearly all of the weapon related posts I've seen when searching for help:
This is NOT for griefing applications, but for friendly little battles in warzone sims and the like.. Probably sci-fi ones.

That aside.

The gun has already been made, and is fired from mouselook, like most. Rezzes the object in front of the gun and propels it in the intended direction.

What I want to happen is for the object to stick to someone, or at least follow their avatar, if it is a successful hit. Upon the successful "stick," I want a small delay before activating some particle scripting.. Then killing the object after another short delay. I can handle the particle effects, but the sticking mechanic is what eludes me.

I'm pretty sure a collision would be the best way to get the "target", but I'm not sure how to keep the object "stuck" to (or at least following) them, preferably sticking to whatever part of their body was hit. I'm kind of a newb when it comes to SL's scripting, though I know a few other languages... Still, I'd appreciate it if someone could give me some working code I can just drop in the object.

Thanks in advance.
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
01-18-2007 14:38
A sticky projectile needs to basically incorporate a nonphysical follow script. On collision, I would advise you to

(a) turn the projectile non-physical;
(b) activate a sensor to detect where the target hit is every X seconds - 0.25 is okay;
(c) have a sensor() event that moves the projectile to wherever the detected position is with llSetPos().

That is just the basic outline, there are other things one can do to better ensure exact correspondence with the av's position at all times, but it should work reasonable well.
_____________________
http://ordinalmalaprop.com/forum/ - visit Ordinal's Scripting Colloquium for scripting discussion with actual working BBCode!

http://ordinalmalaprop.com/engine/ - An Engine Fit For My Proceeding, my Aethernet Journal

http://www.flickr.com/groups/slgriefbuild/ - Second Life Griefbuild Digest, pictures of horrible ad griefing and land spam, and the naming of names
Ephyu Reino
Registered User
Join date: 18 Jan 2007
Posts: 16
01-18-2007 21:23
Hm.. So far, I've got:

CODE

float trackspeed = 0.25;

warpToPos( vector destpos ){
integer jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
if (jumps > 100 )
jumps = 100;
list rules = [ PRIM_POSITION, destpos ];
integer count = 1;
while ( ( count = count << 1 ) < jumps)
rules = (rules=[]) + rules + rules;
llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
}

default {

state_entry(){
llSetBuoyancy(1);
}

collision(integer num_detected) {
string lock = llDetectedName(0);
key lockid = llDetectedKey(0);
llSay(0,"Attached to: " + lock);
llSetStatus(STATUS_PHYSICS , FALSE);
llSensorRepeat(lock,"lockid",AGENT,20000,PI,trackspeed);
}

sensor(integer total_number)
{
vector pos = llDetectedPos(0);
if (llDetectedOwner(0) == llGetOwner())
{
}
else
{
warpToPos(pos);
}

}

}



Buuut it doesn't work. Most it does when I run into it is go non-physical and announce that it's attached to me.

Why does it not move?

EDIT: I've tried the llSetPos, but that doesn't work either, so I'm using the warpToPos script someone referred me to in the above code.
Damanios Thetan
looking in
Join date: 6 Mar 2004
Posts: 992
01-19-2007 07:47
llSensorRepeat(lock,"lockid",AGENT,20000,PI,trackspeed);

Needs to be:

llSensorRepeat("",lockid,AGENT,96,PI,trackspeed);


(lSensorRepeat(string name, key id, integer type, float range, float arc, float rate))
_____________________
Ephyu Reino
Registered User
Join date: 18 Jan 2007
Posts: 16
01-19-2007 12:14
From: Damanios Thetan
llSensorRepeat(lock,"lockid",AGENT,20000,PI,trackspeed);

Needs to be:

llSensorRepeat("",lockid,AGENT,96,PI,trackspeed);


(lSensorRepeat(string name, key id, integer type, float range, float arc, float rate))


Actually, I noticed that and fixed it, but only after I changed something else and got the scripting working.

Right now, I'm having problems getting the object to turn non-physical.

llSetStatus(STATUS_PHYSICS , FALSE);

is the line that doesn't seem to be doing what all the scripting guides I'm reading says it should. It's odd, because the counterpart, llSetStatus(STATUS_PHYSICS , TRUE); seems to be working fine. The object comes out as phyisical, even the original was set to non-physical before adding the script and making a copy.

CODE

collision(integer num_detected) {
if (lockedon == 0){
llSetStatus(STATUS_PHYSICS , FALSE);
lock = llDetectedName(0);
key lockid = llDetectedKey(0);
llSay(0,"Attached to: " + lock);
llSensorRepeat("",lockid,1,2000,PI,trackspeed);
llParticleSystem([PSYS_PART_FLAGS, PSYS_PART_INTERP_SCALE_MASK |
PSYS_PART_EMISSIVE_MASK,
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE,
PSYS_PART_START_COLOR, <.8,.8,1> , PSYS_PART_END_COLOR, <1,1,1> ,
PSYS_PART_START_SCALE, <2,2,0> , PSYS_PART_END_SCALE, <0.1,0.1,0> ,
PSYS_PART_MAX_AGE, .3 , PSYS_SRC_BURST_RATE, .02 ]);
lockedon = 1;
}
}