Jump to content

Help with Zombie Script


KayKendall
 Share

You are about to reply to a thread that has been inactive for 2714 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I am trying to adapt an open source script made for zombies to another smaller object specifically a crocodile. The zombies the script was written for are very tall and when I place the script in the croc it floats well over my head as it follows me. Is there a way to adjust the height in the script I am missing or is there a line that could be added? Obviously I am pretty much a noob and could use some help. Here is the script:

 

//////////////////////////////////////////////////////////
//   (C) Wizardry and Steamworks 2011, license: GPLv3   //
// Please see: http://www.gnu.org/licenses/gpl.html     //
// for legal details, rights of fair usage and          //
// the disclaimer and warranty conditions.              //
//////////////////////////////////////////////////////////
 
// Orientates the primitive's positive z axis 
// towards a position and moves the primitive
// towards that position.
//
// IN: vector representing a position in region
// coordinates.
// OUT: nothing.
moveTo(vector position) {
    llTargetRemove(targetID);
    targetID = llTarget(position, 0.8);
    llLookAt(position, 0.6, 0.6);
    llMoveToTarget(position, 3.0);    
}
 
// Vector that will be filled by the script with
// the initial starting position in region coordinates.
vector iPos;
// Integer that the script will use to detect
// the next target position it will reach.
integer targetID;
 
// Begin script.
default 
{
    state_entry() {
        iPos = llGetPos();
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetRot(llEuler2Rot(<180., 65., 180.>*DEG_TO_RAD));
        llSetStatus(STATUS_PHYSICS, TRUE);
        llSetForce(<0,0,9.81> * llGetMass(), 0);
        llVolumeDetect(TRUE);
        llSetStatus(STATUS_BLOCK_GRAB, TRUE);
        llSensorRepeat("", "", AGENT, 64, TWO_PI, 1);
    }
    sensor(integer num) {
        llSetStatus(STATUS_PHYSICS, TRUE);
        llSetForce(<0,0,9.81> * llGetMass(), 0);
        llVolumeDetect(TRUE);
        llSetStatus(STATUS_BLOCK_GRAB, TRUE);
        llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, TRUE);
        integer nagent = (integer)llFrand(--num);
        if(llGetAgentInfo(llDetectedKey(nagent)) & AGENT_FLYING) return;
        vector dPos = llDetectedPos(nagent);
        moveTo(dPos + <0,0,2.8>);
    }
    no_sensor() {
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetRot(llEuler2Rot(<180., 85., 180.>*DEG_TO_RAD));
 
    }
    on_rez(integer num) {
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetRot(llEuler2Rot(<180., 65., 180.>*DEG_TO_RAD));
        llResetScript();
    }
} 

 

Link to comment
Share on other sites

The line you need to change is 

moveTo(dPos + <0,0,2.8>);

In English, that means something like "move to the same position your target is at, only 2.8 metres above it".

It's difficult to say what offset you should use, since I don't know anything about your crocodile.     The script is taking the target's centre point (i.e. somewhere around the pelvis, for most human avs) and the center of your crocodile's root prim as the start points, so I would suggest something like

moveTo (dPos +<-1.0, 0.0, -0.75> *llDetectedRot(nagent));

That should mean, "1 metre behind the target and 0.75 metres below the target's centre".     The *llDetectedRot(nagent) part means "use the target's frame of reference to calculate the position," so the script knows you want the follower to position itself 1 metre behind the target rather than 1 metre east of it).

If this doesn't help, try looking for "LSL follower" (without quotes) on Google. 

 

Link to comment
Share on other sites

Thank you so much for the help! It did resove the height issue but I still have one issue I need help with as well...the croc is now moving head down and tail up vertically like a human would walk. Is there a way to change the rotation so the crock is horizontal and head first?

Link to comment
Share on other sites

You may need to experiment a little because it's hard to guess from here exactly which direction is supposed to be "forward" on your crocodile.  I'm going to guess, though, that it's the +X axis.  If so, then you'll want to rotate around the Y axis.  There are three places in your script where you'll see the line

        llSetRot(llEuler2Rot(<180., 65., 180.>*DEG_TO_RAD));

So.... the middle number on that rotation vector is the Y axis.  Again, without seeing the crocodile itself, it's hard to guess whether you'll want to rotate clockwise or anticlockwise, so experiment.  Change that 65 to either 155.0 or -25.0 and see what happens.  If it rotates the wrong way, you made the wrong guess.  So put it back the way it was and try again.  If it looks really wonky, then you probably should have rotated around one of the other axes.  Sorry to sound so indecisive, but without seeing the crocodile itself, that's about the best I can do.

Link to comment
Share on other sites

Glad I could help a bit.   

I think you need to make the following changes to get the script to do what you want.    I'm assuming the crocodile is conventionally rotated, from what you said -- that is, if you set the crocodile's rotation to 0,0,0, using the rotation spinners in the edit window, the crocodile's nose is pointing the same direction as is the red direction arrow when you edit the thing.    If it is, then this should work.

First, find the line about llSetForce() in both state_entry(0 and the sensor event, and change it to

llSetForce(<9.81,0.0,0.0> * llGetMass(), 0);

in both cases.   That's telling it to apply the force in the direction of the crocodile's positive x axis (the way the red arrow points when you inspect the creature with the local ruler option selected).

Then -- and this is the more important point -- you need to change the userfunction moveTo(vector position) at the very start of the script.   Locate the line llLookAt(position, 0.6, 0.6); and replace it with 

llRotLookAt( llRotBetween( <1.0, 0.0, 0.0>, llVecNorm( <position.x, position.y, pos.z> - pos ) ), 0.6,0.6 );

That looks scary but let me explain.    llLookAt points the object's z axis towards the target.  That's nice and simple, but not what we want here.  Instead we need llRotLookAt, which points the prim in the direction you specify.    I've simply taken the example in the wiki that points the Y axis in a particular direction, and changed it to point the X axis in that direction.

All that complicated-looking formula means is "calculate the difference between the direction I'm facing -- <1.0,0.0,0.0> -- and the direction I want to look at, without taking into account any difference in the Z axis, and slowly point that way".

Anyway, try that, and see how you get on.

ETA:  I forgot -- find the line

 llSetRot(llEuler2Rot(<180., 65., 180.>*DEG_TO_RAD));

and replace it with llSetRot(ZERO_ROTATION); in all cases (it appears three times).

Link to comment
Share on other sites

Innula,

Thanks again....I had a syntax error on line 17 but when I changed pos to position and moved the ) one space in it saved and worked like i wanted. You folks here are so smart it is truly humbling. Thank you once again and thanks to all who helped :)

This is what I ended up with:

//////////////////////////////////////////////////////////
// © Wizardry and Steamworks 2011, license: GPLv3 //
// Please see: http://www.gnu.org/licenses/gpl.html //
// for legal details, rights of fair usage and //
// the disclaimer and warranty conditions. //
//////////////////////////////////////////////////////////

// Orientates the primitive's positive z axis
// towards a position and moves the primitive
// towards that position.
//
// IN: vector representing a position in region
// coordinates.
// OUT: nothing.
moveTo(vector position) {
llTargetRemove(targetID);
targetID = llTarget(position, 0.8);
llRotLookAt( llRotBetween( <1.0, 0.0, 0.0>, llVecNorm( <position.x, position.y, position.z> - position) ), 0.6,0.6 );
llMoveToTarget(position, 3.0);
}

// Vector that will be filled by the script with
// the initial starting position in region coordinates.
vector iPos;
// Integer that the script will use to detect
// the next target position it will reach.
integer targetID;

// Begin script.
default
{
state_entry() {
iPos = llGetPos();
llSetStatus(STATUS_PHYSICS, FALSE);
llSetRot(ZERO_ROTATION);
llSetStatus(STATUS_PHYSICS, TRUE);
llSetForce(<9.81,0.0,0.0> * llGetMass(), 0);
llVolumeDetect(TRUE);
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
llSensorRepeat("", "", AGENT, 64, TWO_PI, 1);
}
sensor(integer num) {
llSetStatus(STATUS_PHYSICS, TRUE);
llSetForce(<9.81,0.0,0.0> * llGetMass(), 0);
llVolumeDetect(TRUE);
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, TRUE);
integer nagent = (integer)llFrand(--num);
if(llGetAgentInfo(llDetectedKey(nagent)) & AGENT_FLYING) return;
vector dPos = llDetectedPos(nagent);
moveTo (dPos +<-1.0, 0.0, -0.75> *llDetectedRot(nagent));
}
no_sensor() {
llSetStatus(STATUS_PHYSICS, FALSE);
llSetRot(ZERO_ROTATION);

}
on_rez(integer num) {
llSetStatus(STATUS_PHYSICS, FALSE);
llSetRot(ZERO_ROTATION);
llResetScript();
}
}

 

Link to comment
Share on other sites

Glad to help.   Sorry about the typos in my version, and thanks for working it out anyway, and posting the script.

We all of us started out not knowing anything about scripting, and many of us -- certainly me -- learned most of what we know by asking for help in forums like this.    It's not a question of being smart -- just of knowing how the various functions work, which certainly I know only because people have explained them to me.

Anyway, glad you got the crocodile working!

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2714 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...