how can i make object follow other object? - SLUniverse Forums
 
Navigation » SLUniverse Forums > Development Discussion and Support > Scripting » how can i make object follow other object?


Scripting Discuss scripting for SL and other platforms

Reply
 
LinkBack Thread Tools Display Modes
Old 10-28-2009, 12:31 AM   #1 (permalink)
Junior Member
 
Join Date: Oct 2009
Posts: 4
Smile how can i make object follow other object?

how can i make object follow other object?i need that script plz
so-cool is offline   Reply With Quote
Old 10-28-2009, 12:16 PM   #2 (permalink)
Junior Member
 
Join Date: Jul 2009
Posts: 9
Do you want it to be physical or non-physical? If it is non-physical it is fairly straightforward. If it is physical it can be done but there are a number of different ways to do it with varying degrees of difficulty and how nice it looks. I have scripts to do the physical movement. Non-physical movement is fairly straightforward. Get the uuid of the object that you want to follow and then set a timer. You can then use llGetObjectDescription,

LlGetObjectDetails - Second Life Wiki

to get the position and rotation of the object. Then use llSetPrimitiveParams,

LlSetPrimitiveParams - Second Life Wiki

to set the position and rotation in one function call.
Grandma Bates is offline   Reply With Quote
Old 10-29-2009, 03:06 AM   #3 (permalink)
Junior Member
 
Join Date: Oct 2009
Posts: 4
im want non-physical object follow other non-physical, can you write script plz
so-cool is offline   Reply With Quote
Old 10-29-2009, 06:15 AM   #4 (permalink)
The Purple
 
Chalice Yao's Avatar
Kinda at work. Somewhat.
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 3,096
My Mood:
Code:
integer iListener;
key kOwner;
string sTarget;
key kTarget;
vector vTemp;
list rules;
integer count;
integer jumps;
 warpPos( vector destpos ) 
 {   //R&D by Keknehv Psaltery, 05/25/2006
     //with a little poking by Strife, and a bit more
     //some more munging by Talarus Luan
     //Final cleanup by Keknehv Psaltery
     //Changed jump value to 411 (4096 ceiling) by Jesse Barnett
     // Compute the number of jumps necessary
     jumps = (integer)(llVecDist(destpos, llGetPos()) / 10.0) + 1;
     // Try and avoid stack/heap collisions
     if (jumps > 411)
         jumps = 411;
     rules = [ PRIM_POSITION, destpos ];  //The start for the rules list
     count = 1;
     while ( ( count = count << 1 ) < jumps)
         rules = (rules=[]) + rules + rules;   //should tighten memory use.
     llSetPrimitiveParams( rules + llList2List( rules, (count - jumps) << 1, count) );
     if ( llVecDist( llGetPos(), destpos ) > .001 ) //Failsafe
         while ( --jumps ) 
             llSetPos( destpos );
 }
default
{
    state_entry()
    {
        kTarget=NULL_KEY;
        iListener=llListen(123,"",kOwner=llGetOwner(),"");
    }
    on_rez(integer foo)
    {
        if(kOwner!=llGetOwner())
        {
            llListenRemove(iListener);
            iListener=llListen(123,"",kOwner=llGetOwner(),"");
        }
    }
    listen(integer channel, string name, key id, string message)
    {
        sTarget=message;
        llSensor("","",ACTIVE,96,PI);
    }
    no_sensor()
    {
        llOwnerSay("Specified object not found: "+sTarget);
    }
    sensor(integer foo)
    {
        do
        {
            if(!(llDetectedType(foo=~-foo) & AGENT))
                if(llDetectedOwner(foo) == kOwner)
                    if(llSubStringIndex(llToLower(llDetectedName(foo)),llToLower(sTarget)) != -1)
                    {
                        kTarget=llDetectedKey(foo);
                        jump found;
                    }
        }
        while(foo);
        @found;
        if(kTarget != NULL_KEY)
        {
            llOwnerSay("Target found: "+llDetectedName(foo)+", following.");
            llListenRemove(iListener);
            llSetTimerEvent(0.01);
        }
        else
            llOwnerSay("Specified object not found: "+sTarget);
    }
    timer()
    {
        if(llGetAgentSize(kOwner)
        {
            if(vTemp=(llList2Vector(llGetObjectDetails(kTarget,[OBJECT_POS]),0)) != ZERO_VECTOR);
                warpPos(vTemp);
            else
            {
                llOwnerSay("Target vanished. Returning.");
                llSetTimerEvent(0);
                warpPos(llList2Vector(llGetObjectDetails(kOwner,[OBJECT_POS]),0));
                kTarget=NULL_KEY;
                iListener=llListen(123,"",kOwner,"");
            }
        }
        else
        {
            llOwnerSay("Owner vanished. Dieing.");
            llDie();
        }
    }
}
This should do the trick. Drop the script into the object, then just type '/123 thetargetobjectname' in chat and it will search for an object to follow.
__________________
"Have you ever noticed that anybody driving slower than you is an idiot, and anyone going faster than you is a maniac?" - George Carlin

Last edited by Chalice Yao; 10-30-2009 at 04:58 AM.
Chalice Yao is offline   Reply With Quote
Old 10-29-2009, 11:46 PM   #5 (permalink)
Junior Member
 
Join Date: Oct 2009
Posts: 4
not working man (28,0) :Error :Syntax Error
im want object1 follow object 2 by finding key of object 1 when object 1 rez
so-cool is offline   Reply With Quote
Old 10-30-2009, 04:59 AM   #6 (permalink)
The Purple
 
Chalice Yao's Avatar
Kinda at work. Somewhat.
 
Join Date: Dec 2007
Location: Somewhere purple, Germany
Posts: 3,096
My Mood:
Fixed, was a missing closing brace of the warppos function.
Sorry for that, I notoriously write full scripts here while not being able to log into SL at the time of the day ;P
Also, you say object 1 should follow object 2 immediately after rez. What -is- object 2, i.e. what should it be looking out for? What name? I presume both are your objects.
Chalice Yao is offline   Reply With Quote
Old 10-31-2009, 03:03 AM   #7 (permalink)
Junior Member
 
Join Date: Oct 2009
Posts: 4
its ok thank you i will try for solve that
so-cool is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On