Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

some issue with sensorrepeat and llsetpos

Varun Blitz
Registered User
Join date: 22 May 2008
Posts: 62
07-15-2008 00:46
i have made a script for an object which starts sensorrepeat and till the avatar is in range, the object simply calculates the distance between itself and the avatar and then llsetpos to that position.
now the thing is that even if my avatar is at the same position the object with sensor keeps moving either away from the avatar of near towards it. it shud remain at constant distance till the avatar's position is constant.
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
07-15-2008 01:33
What code are you using in the sensor event?
Varun Blitz
Registered User
Join date: 22 May 2008
Posts: 62
07-15-2008 01:44
From: Pedro McMillan
What code are you using in the sensor event?



it's a very simple one.

agent_dist=llVecDist(llGetPos(),llDetectedPos(0));
new_pos=(llDetectedPos(0)+agent_dist;
llSetPos(new_pos);
Varun Blitz
Registered User
Join date: 22 May 2008
Posts: 62
07-15-2008 03:38
help ppl !! plz :(
_____________________
Laugh till the End !!
Beverly Ultsch
Registered User
Join date: 6 Sep 2007
Posts: 229
07-15-2008 05:26
The problem is that lVecDist returns the distance as a float not the direction.

So adding a positive float to a vector will result in strange results.

If I understand what you are tryning to do correctly you probably want

llSetPos(llDetectedPos(0));

This would move the object to the av's position

But remember that llSetPos is limited to 10m so if the distance is further than that you would need to calculate intermediate steps (or use warpos).
Varun Blitz
Registered User
Join date: 22 May 2008
Posts: 62
07-16-2008 04:29
From: Beverly Ultsch
The problem is that lVecDist returns the distance as a float not the direction.

So adding a positive float to a vector will result in strange results.

If I understand what you are tryning to do correctly you probably want

llSetPos(llDetectedPos(0));

This would move the object to the av's position

But remember that llSetPos is limited to 10m so if the distance is further than that you would need to calculate intermediate steps (or use warpos).



i did a printing mistake. sorry !!
it's actually:-
agent_dist=llVecDist(llGetPos(),llDetectedPos(0));
new_pos=(llDetectedPos(0)+agent_dist*llRot2Fwd(llDetectedRot(0));
llSetPos(new_pos);
_____________________
Laugh till the End !!
Varun Blitz
Registered User
Join date: 22 May 2008
Posts: 62
07-16-2008 04:30
From: Beverly Ultsch
The problem is that lVecDist returns the distance as a float not the direction.

So adding a positive float to a vector will result in strange results.

If I understand what you are tryning to do correctly you probably want

llSetPos(llDetectedPos(0));

This would move the object to the av's position

But remember that llSetPos is limited to 10m so if the distance is further than that you would need to calculate intermediate steps (or use warpos).



i did a printing mistake. sorry !!
it's actually:-
agent_dist=llVecDist(llGetPos(),llDetectedPos(0));
new_pos=(llDetectedPos(0)+agent_dist*llRot2Fwd(llDetectedRot(0));
llSetPos(new_pos);

this is the actual piece of code i am using which is giving issues. the one i posted earlier will not even compile.
now can neone explain why the object keeps moving.
_____________________
Laugh till the End !!
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
07-16-2008 09:29
Is it phantom? If not, it won't ever get all the way there, and will move trying to get there (and IIRC, will push the av around as well).

And why use that when it's equivalent to llSetPos(llDetectedPos(0))? If you wanted to go a fraction of the way there, your code would make more sense (multiplying the distance by the fraction). But that would eventually close the distance anyway, unless you stopped moving in when close enough.

I suggest you test the distance for being less than some value, and don't move if you're close enough. That or make it phantom, if it needs to be inside the av.
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
07-16-2008 20:17
From: someone
new_pos=(llDetectedPos(0)+agent_dist*llRot2Fwd(llD etectedRot(0));

Are you aware that llDetectedPos(0) and llDetectedRot(0) will return the position and orientation of the avatar, not the object? The result is that you are basing the new position of your object on the position and facing of the avatar, but then moving *away* as far as the object was to begin with.

Are you simply trying to make the object move gradually towards the avatar to get around the 10m limit of llSetPos()? If that's the case, then what you want to do is probably something like this (sorry if there are bugs... thrown together late at night!):

CODE

// Get the direction and distance from object to avatar
vector dir = llDetectedPos(0) - llGetPos();
vector dist = llVecMag(dir);

// If we are within 10m, then go the whole distance.
// Otherwise go part way
if (dist <= 10.0) {
llSetPos(llDetectedPos(0));
} else {
dir = dir / dist * 10.0;
llSetPos(llGetPos() + dir);
}
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
07-17-2008 07:29
Good point, Pedro -- I wondered about that, but then dismissed it since it's not needed anyway.
LostInKgp Auerbach
Registered User
Join date: 3 Jun 2008
Posts: 4
07-21-2008 03:59
no, i actually want the thing i have metioned in the intial post. the object shud simply detect the rotation of avatar and then moves in that rotation by maintaining the same distance it had from avatar.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
07-21-2008 06:42
Ah, we all misread what you meant by "that position" in your first post.

When the object isn't too close to the avatar, does it work as intended? I believe that it would always put your object in front of the avatar.

You never answered my question about whether the object is phantom. If it works well but only fails when the av is too close, that's probably the cause. It has to be phantom, or SL will move the av. Try it: rez a box, move it until your avatar is inside it, and let go. The avatar will move.

Since English isn't your first language, you'll need to make your sentences short and simple and clear. I faced a similar problem when I worked with Japanese years ago; it's a challenge to write this way but it's worth the effort.