Jump to content

FOLLOW SCRIPT - FUN & NOT SO FUN WITH PHYSICS. I HAVE QUESTIONS...


Pixels Sideways
 Share

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

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

Recommended Posts

Hola!

I have several object follows avatar scripts - slightly different but all have this line to set the prim to physics:

        llSetStatus(STATUS_PHYSICS, TRUE); 

Problem is, I need the objects I'll be putting the script in to not be physical as they will be suspended in mid air when reacting to avatars. 

While the object will follow an avatar from the ground up if the avatar flies up, that's not gonna work.

When I remove set to physics, the object no longer follows. 

So two questions:

1. is setting the object to physical necessary and why and  if so

2. is there a workaround from setting the object to physical? 

Thanks for your help. 

xo

pixels

 

 

 

 

 

Link to comment
Share on other sites

I assume that your follower is using llMoveToTarget, so your basic follower script is something like this example >>  https://wiki.secondlife.com/wiki/LlMoveToTarget#Examples.  That's the way most followers are scripted.  To make that work, you do need to make the follower physical.  As that wiki section wiki tells you, "Only works in attachments and physics-enabled objects." So, no, there is no workaround.

Now, you could script a different sort of follower, for example one that uses a sensor to detect the owner and then uses llSetRegionPos in a timer to keep up as the owner moves around.  That would be very clumsy, though, because you'd be moving the follower in a series of hops instead of along a smooth trajectory. You could also easily outpace the follower by traveling too fast or by traveling across a region boundary. I'm afraid you would be very disappointed in it.

I'm not sure what problem you are trying to solve, though.

19 minutes ago, Pixels Sideways said:

Problem is, I need the objects I'll be putting the script in to not be physical as they will be suspended in mid air when reacting to avatars. 

Why is that a problem?  

  • Thanks 1
Link to comment
Share on other sites

Thanks for your reply.

It's a problem because the follow script turns the object physical and physical objects can not be suspended in mid air as they fall because they are physical.

And these objects need to be in place in mid air prior to avatars engaging with them.  

Here is the annotated script I am using.  

default
{
    state_entry()
    {
        //Get the current position of the object.
        vector pos = llGetPos(); 
        
        //limit-stop obect rotations
        llSetStatus(STATUS_ROTATE_Z,FALSE); 
        llSetStatus(STATUS_ROTATE_Y,FALSE);
        llSetStatus(STATUS_ROTATE_X,FALSE);
        
        //Apply realworld physics.
        llSetStatus(STATUS_PHYSICS, TRUE);
        
        //Wait for 0.1 seconds.
        llSleep(0.1);
        
        //Get the key for the owner of this object.
        key id = llGetOwner();
        
        //Track the location of the owner and updates every 0.4 seconds.
        llSensorRepeat("",id,AGENT,20,2*PI,.4);
    }

        sensor(integer total_number)
    
    {
        //Get the location of object 0, (owner).
        vector pos = llDetectedPos(0);
        
        //Variable used to control the offset.      
        vector offset =<3,0,0>;
        
        //Calculating the offset from the detected position.   
        pos+=offset; 
        
        //Move to new position with 30% motion smoothing.               
        llMoveToTarget(pos,.3);                 
    }
}
 

I also have another script that makes an objet reactive to an avatar that doesn't require physics but it pushes the object away from the avatar.  I think I will have to use that and play wththe vectors and reverse then so it comes toward the avatar instead of away. 

Still curious why physics is necessary for following.

Link to comment
Share on other sites

24 minutes ago, Pixels Sideways said:

I need these to stay on the z axis position and not fly away. 

I can try that tho. Maybe can set the z position to a set region level?

I'm not sure how to do that, tho. 

llSetHoverHeight() or llGroundRepel()

ETA: Setting gravity to 0 often solves a lot of problems for things that don't need gravity; llSetPhysicsMaterial( GRAVITY_MULTIPLIER, 0, 0, 0, 0);

Edited by Quistess Alpha
  • Thanks 1
Link to comment
Share on other sites

6 hours ago, Wulfie Reanimator said:

If the object is using MoveToTarget, it's not really affected by gravity or other forces until the move is stopped.

Actually it is, it just becomes less obvious because move to target is usually strong enough to overpower/out-way most anything else.  The caveat about llMoveToTarget moving slightly faster downwards goes away if gravity is 0.

  • Like 1
Link to comment
Share on other sites

28 minutes ago, Quistess Alpha said:

Actually it is, it just becomes less obvious because move to target is usually strong enough to overpower/out-way most anything else.  The caveat about llMoveToTarget moving slightly faster downwards goes away if gravity is 0.

Yeah, what I said wasn't meant as an absolute. 🙂 The object's movement can also be blocked by other non-physical objects (like solid walls). It can also be displaced if another physical object collides with it hard enough. It will snap back into place.

But for the purposes of a follower, MoveToTarget will work great. The object won't be flying off (if gravity is removed) or falling to the ground, or even wobbling up and down as if constantly fighting gravity.

Edited by Wulfie Reanimator
  • Like 2
Link to comment
Share on other sites

15 hours ago, Pixels Sideways said:

but it pushes the object away from the avatar.

Reading back a bit more carefully, if your object and avatar are close enough to accidentally repel eachother, setting the follower to phantom might help,         llSetStatus(STATUS_PHYSICS|STATUS_PHANTOM, TRUE); just be careful about physical+phantom objects with gravity, especially if you're in a skybox.

Edited by Quistess Alpha
  • Like 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 435 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...