Jump to content

Moving Prim With Collision


Dominic Damiano
 Share

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

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

Recommended Posts

I want to move a torus in random directions while having it detect collisions in X,Y and not Z, but since a torus does not have sides I struggle with this. I have seen some code examples but I do not know how I can apply them to a torus.

vector startpos; 

float Rand(float num) 
{ 
    return (llFrand(2) - 1) * num; 
} 

Move() 
{ 
    vector moveto = <Rand(10),Rand(10),0> + startpos; 
    float time = llFrand(2) + 3; 
    llMoveToTarget(moveto,time); 
    llSetTimerEvent(time); 

} 
      

default 
{ 
    on_rez(integer num) { llResetScript(); } 
     
    state_entry() 
    { 
        llSetBuoyancy(0); 
        llSetStatus(STATUS_PHYSICS,FALSE);//Turns off physics 
        llSetStatus(STATUS_PHANTOM,FALSE);//Turns off phantom 
        startpos=llGetPos(); 
    } 
      
    touch_start(integer total_number) 
    { 
        if(llDetectedKey(0) == llGetOwner()) 
        { 
            state running; 
        } 
    } 
      
collision_start(integer num_detected)
    {
        
        integer i;
        key collider = llDetectedKey(i);
        vector pos = (llDetectedPos(i) - llGetPos()) / llGetRot();
        if ( pos.x > 0){ // play with this line to use different faces
        llSay(0,"ouch");
        }
    }

} 

state running 
{ 
    on_rez(integer num) { llResetScript(); } 
     
    state_entry() 
    { 
        llVolumeDetect(TRUE);
        llSetBuoyancy(1);//allows the object to hover 
        llSetStatus(STATUS_PHYSICS,TRUE);//Turns on physics 
        llSetStatus(STATUS_PHANTOM,TRUE);//Turns on phantom 
        Move(); 
    } 
      
    touch_start(integer total_number) 
    { 
        if(llDetectedKey(0) == llGetOwner()) 
        { 
            llSetPos(startpos); 
            llSetTimerEvent(0); 
            state default; 
        } 
    } 
      
    timer() 
    { 
        Move(); 
    } 
} 

 

 

Link to comment
Share on other sites

All objects have faces, but that's not particularly relevant to your project.  You seem to want to know whether someone has collided with the local +X side of the object or the -X side.  (Look at your torus with the Build editor set to the Local frame of reference to see which way the X-axis points.) Your collision_start event will almost do that now.  There are a couple of tactical (and syntactic) things to pay attention to:

1.  Your variable i doesn't do anything practical, although it will work by accident since it always has the value 0.  The llDetectedKey() function is expecting you to tell it which colliding avatar to respond to.  That's the value reported in your script as num_detected .  In almost all cases, you want to look at llDetectedKey(0), the first collider.  Forget i.

2. I'm not sure what you expect the collision_start event to do ultimately, but if you want to use it to trigger a state change, the way you are using touch_start, you really should use collision_end (and touch_end) instead.  If you use the _start versions of those functions, any information about the collision or touch is likely to be lost before you enter the new state.  As with my first point, it doesn't make much difference in your project because you are not carrying any information from one state to the other.  Still, it's one of those things to be aware of if you make this script or a future one more complicated.

  • Thanks 1
Link to comment
Share on other sites

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