Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Vehicles behavior making me INSANE!

Ilsa Munro
Registered User
Join date: 1 Apr 2008
Posts: 29
08-19-2008 15:20
Ahem... I'm working on a script for a blimp. Here's what I want to happen. I sit on it, I press page up, and it goes straight up. I press page down and it goes straight down. Seems simple enough doesn't it?

Here's what's actually happening. I sit on it and press page up and it goes up and forward. I press page down and it goes down and forward. There's sufficient acceleration in the forward movement that a few up and down cycles get me moving faster than the linear motor pushes me on the forward axis in normal use.

Here's the very pared down script that I'm testing with:

CODE

vector avPosition = <0.0, 0.0, 0.50>;
rotation avRotation = ZERO_ROTATION;
integer sit;
string anim = "sit";
rotation curRot;
key owner;
//
// Simple flight variables
//
float Speed = 0;
float Turn = 0;
float Lift = 0;
integer Move = FALSE;
integer Turning = FALSE;

default
{
state_entry()
{
llSitTarget(avPosition, avRotation);
llSetCameraEyeOffset(<-5, 0, .5>);
llSetCameraAtOffset(<1, 1, .5>);
llSetSitText("Fly");
llCollisionSound("", 0.0);
//
// Linear motor
//
llSetVehicleType(VEHICLE_TYPE_AIRPLANE);
llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <100, 10, 10> );
llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 3 );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 3 );
//
// agular motor
//
llSetVehicleVectorParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, <.5, .5, .5>);
llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.2 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.3);
//
// hover
//
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 0 );
llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY, 0 );
llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 1000 );
llSetVehicleFloatParam( VEHICLE_BUOYANCY, 0.99 );
//
// linear deflection
//
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 2 );
//
// angular deflection
//
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 1);
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 2);
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.4 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, .6 );
//
// banking
//
llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, .7);
llSetVehicleFloatParam( VEHICLE_BANKING_MIX, .5);
llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 0.2);
//
// default rotation of local frame
//
llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0,0,0,1>);
//
// Flags
//
llRemoveVehicleFlags( VEHICLE_FLAG_NO_DEFLECTION_UP
| VEHICLE_FLAG_HOVER_WATER_ONLY
| VEHICLE_FLAG_HOVER_TERRAIN_ONLY
| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
| VEHICLE_FLAG_HOVER_UP_ONLY
| VEHICLE_FLAG_LIMIT_ROLL_ONLY
| VEHICLE_FLAG_LIMIT_MOTOR_UP );
}

on_rez(integer num)
{
llSetStatus(STATUS_PHYSICS, FALSE);
llStopSound();
llReleaseControls();
sit = FALSE;
curRot = llGetRot();
llSetRot(<0, 0, curRot.z, curRot.s>);
llResetScript();
}

changed(integer change)
{
if(change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if((agent == NULL_KEY) && (sit))
{
llSetStatus(STATUS_PHYSICS, FALSE);
llReleaseControls();
sit = FALSE;
}
else if((agent == llGetOwner()) && (!sit))
{
llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
sit = TRUE;
rotation atNow = llGetRot();
llSetRot(<0, 0, atNow.z, atNow.s>);
llSetStatus(STATUS_PHYSICS, TRUE);
llStartAnimation(anim);
}
}
}

run_time_permissions(integer perm)
{
if (perm & (PERMISSION_TAKE_CONTROLS))
{
llTakeControls(CONTROL_UP | CONTROL_DOWN | CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);
}
}

control(key id, integer level, integer edge)
{
if (level & CONTROL_FWD)
{
// Speed = 1; // fwd power
// Move = TRUE;
}
if (level & CONTROL_BACK)
{
// Speed = -1; // reverse power
// Move = TRUE;
}
if (level & CONTROL_UP)
{
Lift = 1; // up speed
Move = TRUE;
}
if (level & CONTROL_DOWN)
{
Lift = -1; // down speed
Move = TRUE;
}
if ((level & CONTROL_ROT_RIGHT) || (level & CONTROL_RIGHT))
{
// Turn = 1; // right turn/bank speed
// Turning = TRUE;
}
if ((level & CONTROL_ROT_LEFT) || (level & CONTROL_LEFT))
{
// Turn = -1; // left turn/bank speed
// Turning = TRUE;
}
if(Move)
{
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, Lift>);
Lift = 0;
Speed = 0;
Move = FALSE;
}
if(Turning)
{
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <Turn,0,0>);
Turn = 0;
Turning = FALSE;
}
}
}


As you can see I've gone so far as to disable all of the control processing other than Page Up / Down and I still pick up forward motion.

I've also gone so far as to eliminate the use of the vehicle library to move up and down and used llApplyImpulse along the Z axis which lifts the test prim just fine, but I STILL wind up moving forward.

Clearly I'm monkeying something up but for the life of me I have no idea what. For my fragile tattered sanity can anyone point ot where I'm going astray?

Thanks
Ilsa Munro
Registered User
Join date: 1 Apr 2008
Posts: 29
08-19-2008 17:10
Huge massive gigantic thanks to Revochen Mayne who just gave me my solution. With his very kind premission here's the soution - and it's so simple I don't even need to re-post the code:

In the linear settings change:

llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <100, 10, 10> );

to

llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <0,0,10> );

And in the angular settings change:

llSetVehicleVectorParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, <.5, .5, .5>;);

to

llSetVehicleVectorParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, <0,0, .5>;);

I'm still working on understanding the whys, but at least I now go up when I go up.

Thanks so much for all your help!
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
08-19-2008 21:52
I think you might want both the linear deflection efficiency and the angular deflection efficiency to be zero (and I'd make their time scales very large as well). The former tends to redirect linear motion toward the vehicle's x-axis. The latter tends to turn the vehicle's x-axis in the direction of motion (e.g. pitching up if it is moving upward).