Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

1000 L to the first person who helps me with working script

Kain Cleaver
Registered User
Join date: 24 Jan 2006
Posts: 178
02-04-2007 20:27
I need a Follower script that takes babysteps insted of instantly going to the senced object

the object needs to rotate towards its victim and move about .1 - .5 m per movement

think of the object like a zombie looking for its victim and moving towards it slowly

im shooting for a non physics solution'

thank you
Tomfox Wiranata
Registered User
Join date: 20 Dec 2006
Posts: 80
02-05-2007 00:44
Hello Kain,

what do you mean by non physics? Did I get this right? You need some kind of a robot who follows people?
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
02-05-2007 00:49
hmm, a basic pet follower script should work.
How you initiate the target is left for you to decide, thsi will just 'attack' any nearby targets
The following should work.

CODE

float Speed = 0.5; // maximum speed of Item m/s
float TimeToFind = 4.0; // How Often to sense the target
float Range = 20.0; // How far to sense targets
vector offset =<-0.5,0,0>; // How close to get

startup()
{
}

default
{
state_entry()
{
llSetStatus(STATUS_ROTATE_Z,FALSE);
llSetStatus(STATUS_PHYSICS, FALSE);
llSensorRemove();
}

touch_start(integer changes)
{
state Shuffle;
}
}

state Shuffle
{
state_entry()
{
llSetStatus(STATUS_ROTATE_Z,TRUE);
llSetStatus(STATUS_PHYSICS, TRUE);
// Attracted to any agents in the area
llSensorRepeat("","",AGENT,Range,2*PI, TimeToFind);
}

touch_start(integer changes)
{
state default;
}

sensor(integer total_number)
{
// Will alwasy move to the closest one.
vector current = llGetPos();
vector pos = llDetectedPos(0);
vector delta = pos - current;
float RangeToTarget = llSqrt(((delta .x * delta .x) + (delta .y * delta .y)))
float TimeToTarget = RangeToTarget / Speed;
llMoveToTarget(pos+offset*llDetectedRot(0), TimeToTarget);
llLookAt(pos, .1 , 1);
}
}


Could probably add a timer event to the default state , to make then shuffle around in circles when there are no targets.
Lee Ponzu
What Would Steve Do?
Join date: 28 Jun 2006
Posts: 1,770
02-05-2007 11:50
Here is the basic geometry information.

Given two positions,

vector p1
vector p2

A vector path (like an arrow) from p2 to p1 is

vector path = p1 - p2;

path is one big step. If you only want to go half way, use path/2.0, etc.

Now, please don't take this the wrong way...if this is all new to you, you should try to find some tutorial about 3D graphics and vector algebra/geometry on the WWW that you can study to get the basics.

Good luck.
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
02-06-2007 08:01
Are you moving an avatar (making it walk), or moving an object?
Learjeff Innis
musician & coder
Join date: 27 Nov 2006
Posts: 817
02-06-2007 08:03
But rather than thinking of fractions on the path, think about moving down the path at the desired rate of .1 m/s or whatever.
JoeTheCatboy Freelunch
Registered User
Join date: 14 Jun 2006
Posts: 42
02-08-2007 16:49
take the normalized vector of the path and multiply it by how many meters you want to go.

llVecNorm(pos - targetpos) * .5 will make it move half a meter towards the target.