Jump to content

trying to understand a vehicle script.. what if I want the driver to have 2 or 3 different anims?


Sca Shilova
 Share

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

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

Recommended Posts

Hi, 

I've been using to try make a trolly to rezz and push, that can have one seated passenger.

The vehicle script in the SL freebie Bus to Nowhere with explanations that has helped. I managed to tweak it to get the animated avatar in the right place, and to slow it down to walking pace. I also took out the engine sounds. For the passenger, I added a prim with an embedded sit pose. Linking everything seems to work. 

(Also probably good to mention the the freebie bus I mentioned contains another script to deal with region crossings.)

Can someone help me adding to the script so that the avatar who pushes the trolly has a different animation when standing still. 

I already made both animations, and the walking one (or if it were a vehicle, the driver anim) works already.

This is the script so far. I'm certain there's a way more elegant way to do it all, but I'm a total dummy at this and trying to learn :)

Thanks!

-----------------------------------------------

//Basic Motorcycle Script
//
// by Cory
// commented by Ben

//The new vehicle action allows us to make any physical object in Second Life a vehicle. This script is a good example of a 
// very basic vehicle that is done very well.  

integer loopsnd = 0;

default
{   

    //There are several things that we need to do to define vehicle, and how the user interacts with it.  It makes sense to 
    // do this right away, in state_entry.
    state_entry()
    {
        
        //We can change the text in the pie menu to more accurately reflecet the situation.  The default text is "Sit" but in 
        // some instances we want you to know you can drive or ride a vehicle by sitting on it. The llSetSitText function will
        // do this.
        llSetSitText("Ride me!");
        
        //Since you want this to be ridden, we need to make sure that the avatar "rides" it in a acceptable position
        // and the camera allows the driver to see what is going on. 
        //
        //llSitTarget is a new function that lets us define how an avatar will orient itself when sitting.
        // The vector is the offset that your avatar's center will be from the parent object's center.  The
        // rotation is bassed off the positive x axis of the parent. For this motorcycle, we need you to sit in a way
        // that looks right with the motorcycle sit animation, so we have your avatar sit slightly offset from the seat.
       llSitTarget(<-1.43, 0.045, 0.015>, ZERO_ROTATION);
        
        
        llSetCameraEyeOffset(<-9.0, -0.00, 4.0>);
        llSetCameraAtOffset(<3.0, 0.0, 2.0>);
        
        llSetVehicleFlags(-1);
        llSetVehicleType(VEHICLE_TYPE_CAR);
        
        llSetVehicleFlags(VEHICLE_FLAG_NO_FLY_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.2);
        llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.80);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.10);
        llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.10);
        llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.3);
        llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.2);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.3);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.1);
        llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000.0, 2.0, 1000.0>);
        llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <10.0, 10.0, 1000.0>);
        llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.90);
        llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.90);
        llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0.05);
        llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.1);
     
    }
    
    changed(integer change)
    {
        
        if (change & CHANGED_LINK)
        {
           key agent = llAvatarOnSitTarget();
            
            if (agent)
            {
                if (agent != llGetOwner())
                {
                    llSay(0, "Sorryyy but nice try! :D");
                    llUnSit(agent);
                    llPushObject(agent, <0,0,20>, ZERO_VECTOR, FALSE);
                }
                
                else
                {
                    llSetStatus(STATUS_PHYSICS, TRUE);
                   llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS );
                }
            }
            else
            {
                llSetStatus(STATUS_PHYSICS, FALSE);
                llReleaseControls();
                llStopAnimation("sit");
            }
        }
        
    }
    
    run_time_permissions(integer perm)
    {
        if (perm)
        {
            llStopAnimation("sit");
            llStartAnimation("grannyWalkNew3");
            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);
        }
    }
    control(key id, integer level, integer edge)
    {
        
        vector angular_motor;

        if (level & edge & CONTROL_FWD)
        {
            
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <2,0,0>);
            
        }
        else if ((edge & CONTROL_FWD) && ((level & CONTROL_FWD) == FALSE))
        {
            
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0,0,0>);
            
            loopsnd = 0;
        }
        else if (level & CONTROL_FWD)
        {
            
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <2,0,0>);
            
          
       }
        
        if(level & CONTROL_BACK)
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <-2,0,0>);
        }
        if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
        {
            angular_motor.x += 100;
            angular_motor.z -= 100;
        }
        if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
        {
            angular_motor.x -= 100;
            angular_motor.z += 100;
        }
        if(level & (CONTROL_UP))
        {
            angular_motor.y -= 50;
        }
    
        llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
    }
    
}
 

 

Link to comment
Share on other sites

The first thing that comes to mind is to utilise the moving_start and moving_end events, starting the appropriate animation and stopping the inappropriate one in each:

moving_start ()
{
    llStartAnimation ("pushing");
    llStopAnimation ("standing still");
}

moving_end ()
{
    llStartAnimation ("standing still");
    llStopAnimation ("pushing");
}

 

Link to comment
Share on other sites

If that doesn't work as well as you'd like it'd be worth seeing how it goes putting the start and stop animation calls in the control event so they're triggered directly by the control keys. You mention that you took the sounds out of the original script: you'd want to put the animation triggers in the same places that those were. Doing that would also open up the possibility of different animations for reversing or turning.

Link to comment
Share on other sites

okay.

I tried your first suggestion but I don't know enough about scripting to know where exactly and how to add it, so it didn't work.

I still have the original script, so I will try your next suggestion now, thanks :)

 

Edited by Sca Shilova
Link to comment
Share on other sites

If you create a new script you'll see it responds to two events: state_entry and touch_start. The script you posted has handlers for the state_entry, changed, run_time_permissions and control events. You just add the moving_start and moving_end events like any of those:

default
{
    state_entry ()
    {
        //stuff you do in this event
    }
    changed (integer changes)
    {
        //stuff you do in this event
    }
    some_other_event (some_other_parameters)
    {
        //stuff you do in this event
    }
    moving_start ()
    {
        //stuff you do in this event
    }
    moving_end ()
    {
        //stuff you do in this event
    }
}

The order the events appear in the script doesn't matter. When the script is running it waits until the simulator tells it something has happened that it's interested in, like something about the object it's in has changed, or that the object it's in has started or stopped moving, and then the code relevant to that event gets executed.

Edited by KT Kingsley
Premature submission
Link to comment
Share on other sites

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