Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Changing Avatar Animation in Vehicle (Obvious Noob Question)

Artanis Exonar
Registered User
Join date: 21 Jul 2008
Posts: 1
07-25-2008 08:41
I'm using a public domain airplane script I found on the web and I am trying to change the avatar animation from sitting to standing. I have tried several methods that at least in my mind should have worked but obviously since they haven't, more knowledge of SLS is required. Start and StopAvatarAnimation functions with "stand" have been tried with no success but it is more likely that I am just using them wrong. Is there a simple way of inserting or implementing a change of avatar animation on an object with a flat surface using this plane script? What might I be able to do or can someone correct me? I'm not worried about the avatars position on the object as I can easily edit that.


Current script: Same as public domain airplane script as follows -

// assumes that the root primitive is oriented such that its
// local x-axis points toward the nose of the plane, and its
// local z-axis points toward the top

// control flags that we set later
integer gAngularControls = 0;
integer gLinearControls = 0;

// we keep track of angular history for more responsive turns
integer gOldAngularLevel = 0;

// the linear motor uses an accumulator model rather than keeping track
// of the linear control level history
vector gLinearMotor = <0, 0, 0>;

default
{
state_entry()
{
llSetSitText("Fly";);
llCollisionSound("", 0.0);

// the sit and camera placement is very shape dependent
// so modify these to suit your vehicle
llSitTarget(<0.6, 0.0, 0.20>, ZERO_ROTATION);
llSetCameraEyeOffset(<-10.0, 0.0, 2.0> );
llSetCameraAtOffset(<3.0, 0.0, 1.0> );

llSetVehicleType(VEHICLE_TYPE_AIRPLANE);

// weak angular deflection
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.1);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 1.0);

// strong linear deflection
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 1.0);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.2);

// somewhat responsive linear motor
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.5);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 20);

// somewhat responsive angular motor, but with 3 second decay timescale
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.5);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 3);

// very weak friction
//llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000.0, 1000.0, 1000.0> ); // CUBEY - original line
llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <200, 20, 20> ); // CUBEY - increased friction
llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <1000.0, 1000.0, 1000.0> );

llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.65); // almost wobbly - CUBEY - increased from .25 to improve stability
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 1.5); // mediocre response

llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0.4); // medium strength
llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.1); // very responsive
llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.95); // more banking when moving

// hover can be better than sliding along the ground during takeoff and landing
// but it only works over the terrain (not objects)
//llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, 3.0);
//llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.5);
//llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 2.0);
//llSetVehicleFlags(VEHICLE_FLAG_HOVER_UP_ONLY);

// non-zero buoyancy helps the airplane stay up
// set to zero if you don't want this crutch
llSetVehicleFloatParam(VEHICLE_BUOYANCY, 0.2);

// define these here for convenience later
// CUBEY - modified these as per Shadow's prefs
gAngularControls = CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_BACK | CONTROL_FWD;
gLinearControls = CONTROL_UP | CONTROL_DOWN;

llSetStatus(STATUS_PHYSICS, FALSE); //CUBEY - ensure that physics are disabled when plane is rezzed so it doesn't fly off
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
if (agent != llGetOwner())
{
// only the owner can use this vehicle
llSay(0, "You aren't the owner -- only the owner can fly this plane.";);
llUnSit(agent);
llPushObject(agent, <0,0,10>, ZERO_VECTOR, FALSE);
}
else
{
// clear linear motor on successful sit
gLinearMotor = <0, 0, 0>;
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, gLinearMotor);

//llSetStatus(STATUS_PHYSICS, TRUE);
llSetVehicleFloatParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, 1000.0);
llSetVehicleFloatParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, 1000.0);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
}
else
{
// stop the motors
gLinearMotor = <0, 0, 0>;
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, gLinearMotor);
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, gLinearMotor);

// use friction to stop the vehicle rather than pinning it in place
//llSetStatus(STATUS_PHYSICS, FALSE);
llSetVehicleFloatParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, 1.0);
llSetVehicleFloatParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, 1.0);

// driver is getting up
llReleaseControls();
llStopAnimation("sit";);
llSetStatus(STATUS_PHYSICS, FALSE); //CUBEY - turn off physics to make sure the parked plane can't be moved
}
}

}

run_time_permissions(integer perm)
{
if (perm)
{
llStartAnimation("sit";);
llTakeControls(gAngularControls | gLinearControls, TRUE, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE); //CUBEY - enable physics when avatar sits
}
}

control(key id, integer level, integer edge)
{
// only change linear motor if one of the linear controls are pressed
vector motor;
integer motor_changed = level & gLinearControls;
if (motor_changed)
{
if(level & CONTROL_UP) //CUBEY
{
if (gLinearMotor.x < 0)
{
gLinearMotor.x = 0;
}
else if (gLinearMotor.x < 30)
{
gLinearMotor.x += 5;
}
motor_changed = TRUE;
}
if(level & CONTROL_DOWN) //CUBEY
{
if (gLinearMotor.x > 0)
{
gLinearMotor.x = 0;
}
else if (gLinearMotor.x > -30)
{
gLinearMotor.x -= 5;
};
motor_changed = TRUE;
}
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, gLinearMotor);
}

// only change angular motor if the angular levels have changed
motor_changed = (edge & gOldAngularLevel) + (level & gAngularControls);
if (motor_changed)
{
motor = <0,0,0>;
if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
{
// add roll component ==> triggers banking behavior
motor.x += 10;
}
if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
{
motor.x -= 10;
}
if(level & (CONTROL_BACK)) // CUBEY
{
// add pitch component ==> causes vehicle lift nose (in local frame)
motor.y -= 8;
}
if(level & (CONTROL_FWD)) // CUBEY
{
motor.y += 8;
}
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, motor);
}
// store the angular level history for the next control callback
gOldAngularLevel = level & gAngularControls;
}
}
Taeas Stirling
Registered User
Join date: 4 Sep 2004
Posts: 74
07-25-2008 12:55
once you have perm's, you need to stop the sit anim before starting the standing anim, and make sure you have a copy of the standing anim in the root prim of the vehicle.

llStopAnimation("sit";);
llStartAnimation("standing";);
Kayaker Magic
low carbonated footprint
Join date: 11 Sep 2008
Posts: 109
06-01-2009 15:59
I had strange problems with switching from "sit" to "stand" that were solved by throwing in a call to llSleep(0.1); between the llStopAnimation("sit";); and the llStartAnimation("stand_2";);
(I used one of the built in stands, it was not necessary to put any animations in my contents).