Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Broken Vehicle Script

Valradica Vanek
Registered User
Join date: 1 Aug 2006
Posts: 78
09-04-2006 18:02
I have been pouring through the wiki, sample scripts and the vehicles tutorial working on a simpel hover scooter. I am sure (of course) that I have everything right and have copy/pasted stuff directly from every sample of code I found - When ever I run the script, my scooter just falls to the ground and rolls over on me. (ouch) I've messed with everything including the vertical attractor, bouyancy, etc, but all it does is the same -

Attached is the script - permissions work fine, the controls event is infantile because the scooter won't even hover initially - is there some specific order in which things need to be initialize for this to work?

Val ---

// these variables contain the motion charactaristics of the skooter
float ForVel = 0.0;
float UpVel = 0.0;
// control flags that we set later
integer gAngularControls = 0;
integer gLinearControls = 0;

// Hover controls
float HoverHeight;
float HoverInc = 2.0;
float HoverMax = 40.0;
float HoverInit = 2.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>;

set_vehicle_params ()
{
llOwnerSay ("Re-Setting Vehicle Parameters";);

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

// uniform linear friction
llSetVehicleFloatParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, 5 );

// uniform angular friction
llSetVehicleFloatParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, 10 );

// linear motor
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_OFFSET,<0, 0, 0>;);
llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 5 );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 60 );

// angular motor
llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 6 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 10 );

// hover
HoverHeight = HoverInit;
llOwnerSay("initial Hover Height = " + (string) HoverInit);
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, HoverHeight);
llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY, 1.0 );
llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 2 );
llSetVehicleFloatParam( VEHICLE_BUOYANCY, 1.0 );

// no linear deflection
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, .5 );
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 5 );

llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.8); // almost wobbly
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 1.5); // mediocre response

// no angular deflection
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, .5 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 5 );

// no vertical attractor
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, .8 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 2 );

// no banking
//llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, .5 );
//llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 0.7 );
//llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 5 );

// default rotation of local frame
llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );

// remove all flags
llRemoveVehicleFlags( VEHICLE_FLAG_HOVER_WATER_ONLY
| VEHICLE_FLAG_LIMIT_ROLL_ONLY
| VEHICLE_FLAG_HOVER_TERRAIN_ONLY
| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
| VEHICLE_FLAG_HOVER_UP_ONLY
| VEHICLE_FLAG_LIMIT_MOTOR_UP );

// set the physic status
llSetStatus (STATUS_PHYSICS | STATUS_RETURN_AT_EDGE, TRUE);


}

default
{
state_entry()
{
llListen( 0, "", NULL_KEY, "" );
}

listen( integer channel, string name, key id, string message )
{

if ( id == llGetOwner() && message == "Start Skooter";)
{
llWhisper( 0, "Sky Skooter Activated" );
llSetColor (<0.0,1.0,0.0>,ALL_SIDES);

if (llGetPermissions() & PERMISSION_TAKE_CONTROLS)
{
//llReleaseControls();
}
else
{
llRequestPermissions(id, PERMISSION_TAKE_CONTROLS);
}
// set vehicle parameters
set_vehicle_params();
// activate controls



}

else if ( id == llGetOwner() && message == "Stop";)
{
llWhisper( 0, "Sky Skooter Deactivated" );
llSetColor (<1.0,0.0,0.0>,ALL_SIDES);
llSetStatus (STATUS_PHYSICS, FALSE);
//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);
//this diables the vehicle
llSetVehicleType(VEHICLE_TYPE_NONE);
llReleaseControls();

// interpret message
}
else
{
//llWhisper( 0, "You're not the boss of me." );
// etc.
}
}


run_time_permissions(integer perms)
{
llOwnerSay("run_time_permissions";);
integer desired_controls =
CONTROL_FWD |
CONTROL_BACK |
CONTROL_LEFT |
CONTROL_RIGHT |
CONTROL_ROT_LEFT |
CONTROL_ROT_RIGHT |
CONTROL_UP |
CONTROL_DOWN |
CONTROL_LBUTTON |
CONTROL_ML_LBUTTON;

if (perms & PERMISSION_TAKE_CONTROLS) {
llTakeControls(desired_controls, TRUE, FALSE);
}
}

control(key id, integer held, integer change)
{
integer pressed = held & change;
integer down = held & ~change;
integer released = ~held & change;
integer inactive = ~held & ~change;

//llOwnerSay("control";);
if (pressed & CONTROL_FWD || down & CONTROL_FWD)
{
ForVel = ForVel + .1;
llOwnerSay((string) ForVel);
llSetVehicleVectorParam (VEHICLE_LINEAR_MOTOR_DIRECTION, <ForVel, 0, 0> );
}
if (pressed & CONTROL_UP)
{
if (HoverHeight < HoverMax)
{
HoverHeight = HoverHeight + HoverInc;
llOwnerSay("HoverHeight = " + (string) HoverHeight);
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, HoverHeight);
}
}

if (down & CONTROL_UP) llOwnerSay("Up held";);
if (pressed & CONTROL_DOWN)
{
if (HoverHeight > HoverInc+ 1.0)
{
HoverHeight = HoverHeight - HoverInc;
if (HoverHeight < HoverInit) HoverHeight = HoverInit;
llOwnerSay("HoverHeight = " + (string) HoverHeight);
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, HoverHeight);
}


}
if (down & CONTROL_DOWN) llOwnerSay("Down held";);
if (pressed & CONTROL_BACK ||down & CONTROL_BACK) {
//ForVel = ForVel - .1;
//llOwnerSay((string) ForVel);
llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, <ForVel, 0, 0> );
}
}
}
Seagel Neville
Far East User
Join date: 2 Jan 2005
Posts: 1,476
09-04-2006 20:42
Sorry, I give up. :o
Please use PHP tag.... I missed much and will confuse you much more. :D

What about using this script based on it?
_____________________
:) Seagel Neville :)
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
09-05-2006 00:42
I didn't go through the whole script.. but probably will sometime soon to see if i can make a vehicle myself..

But I do remember seeing a hover scooter in game.. (er.. hover moterbike. not neccessarily a "scooter";) and I saw what it does for stability.

Put a couple flat, semi-wide, completely transparent prims on the ground, in front of and behind the scooter.

It'll stay upright then.
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
09-05-2006 05:43
Just as a note, as this is something I've seen people forget to do, but what it appears your problem is from the sound of what happens to the scooter (the flip and roll thing) is usually due to the root prim being improperly oriented.

If you have a prim for the root that this script is in set to be rotation to something like 180,180,180...then it's going to flip and flop and do all kinds of crazy things when the vehicle starts up.

What you need? The root prim in a vehicle should always be able to be set to 0,0,0 rotation without making it become unlevel. I usually start with a seat and point it due east to 0,0,0; and then build onto it from there.
Valradica Vanek
Registered User
Join date: 1 Aug 2006
Posts: 78
Broken Script Solution!!
09-05-2006 09:19
Ok, so I think in my sleep and after spending probably 6 hours on this problem, I had an AHA and it worked. BTW, This detail was not mentioned in any of the turtorials so here it is:

I had put the script into one of the prims in the skooter rather than the linked skooter itself. I had a control module prim which contained the script, but most of it did not translate to the whole skooter - geesh! The call to make the thing physical worked and the whole skooter crashed to the ground.

When I took the script out of the control module prim and put it at the vehicle level it worked as advertized. Perhaps this is obvious, but I have different scripts in different parts of the skooter that do different things and they work fine. None of the tutorials or other forum threads that I found mentioned that the vehicle control script must be at the vehicle assembly level.

Hope this is helpful - sorry to have wasted any of your time.
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
09-05-2006 12:56
Actually, when you put the script in after linking the vehicle togeather, what you're doing is putting it into the root prim (the last prim selected before linking).

This can be proven. Take three or four prims and put them together, then change the name on one of the prims. Select the other prims then select the one you changed the name on last, and link. The whole object gets the name of that last prim you selected.

Select any other object last and the whole object gets' the name stored in that object.

So when you select a linked object and edit, what you're actually seeing is the last object selected, or the Root Prim.