CODE
default
{
state_entry()
{
// what the pie menu says if you want to get in
llSetSitText("Ride");
// hearing collision sounds when on the ground would suck, so we mute them.
llCollisionSound("", 0.0);
// where the AV sits (this assumes that the root prim is the drivers seat)
llSitTarget(<0.6, 0.05, 0.20>, ZERO_ROTATION);
// readjust the camera so the driver can see
llSetCameraEyeOffset(<-5.0, 0.0, 2.0>);
llSetCameraAtOffset(<3.0, 0.0, 2.0>);
// resets the vehicle flags
llSetVehicleFlags(-1);
// define the vehicle as a vehicle and what kind it will be
// possibilities inclide:
// VEHICLE_TYPE_SLED
// VEHICLE_TYPE_CAR
// VEHICLE_TYPE_BOAT
// VEHICLE_TYPE_AIRPLANE
// VEHICLE_TYPE_BALLOON
llSetVehicleType(VEHICLE_TYPE_CAR);
// flags to set special attributes or behaiviors to the craft
// VEHICLE_FLAG_NO_DEFLECTION_UP Prevents linear deflection parallel to the
// world-z axis. or in plain english linear deflection will not push up
// VEHICLE_FLAG_LIMIT_ROLL_ONLY Removes vertical attraction for changes in
// vehicle pitch allows craft that use vertical attraction to nose up/down
// VEHICLE_FLAG_HOVER_WATER_ONLY Hover only pays attention to water level
// hover keeps craft at a fixed height above the water height (ignoring terrain height)
// VEHICLE_FLAG_HOVER_TERRAIN_ONLY Hover only pays attention to terrain height
// hover keeps craft at a fixed height above the terrain height (ignoring water height)
// VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT Hover only pays attention to global height
// hover at global altitude ignoring terrain and water levels
// VEHICLE_FLAG_HOVER_UP_ONLY Hover only pushes up
// hover will not push down, hover height will be the lowest the craft can go
// VEHICLE_FLAG_LIMIT_MOTOR_UP Prevents ground vehicles from motoring into the sky
// keeps ground craft from flying up or steering midair
//
// VEHICLE_FLAG_MOUSELOOK_STEER Makes vehicle try to turn toward mouselook direction
// VEHICLE_FLAG_MOUSELOOK_BANK Makes vehicle try to turn toward mouselook
// direction assuming banking is enabled
// VEHICLE_FLAG_CAMERA_DECOUPLED Causes the camera look-at axis to NOT
// move when the vehicle rotates
// flags we are not applying to this craft.
// may be unneccessary unless craft will change flags when entering different modes
// but seems like a good idea o have them anyway. if the craft will change modes
// i.e. enter a staet to be a car not an airplane then you would remove the airplane
// type flags and add car type ones.
llRemoveVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP
| VEHICLE_FLAG_HOVER_WATER_ONLY
| VEHICLE_FLAG_HOVER_TERRAIN_ONLY
| VEHICLE_FLAG_LIMIT_MOTOR_UP
| VEHICLE_FLAG_LIMIT_ROLL_ONLY
| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
| VEHICLE_FLAG_HOVER_UP_ONLY);
// flags we are applying to this craft
llSetVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP
| VEHICLE_FLAG_LIMIT_MOTOR_UP
| VEHICLE_FLAG_LIMIT_ROLL_ONLY
| VEHICLE_FLAG_MOUSELOOK_STEER
| VEHICLE_FLAG_MOUSELOOK_BANK
// | VEHICLE_FLAG_CAMERA_DECOUPLED
);
// no deflection = (0.0) max deflection = 1.0
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.00);
// no deflection = (0.0) max deflection = 1.0
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 1.0);
// angular deflection: an outside push will attempt to reorient craft
// to match direction of push.
// i.e. a collision from the side will turn the craft to point
// the same direction as the impact was going.
// time till craft twists to match direction of outside push
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.06);
// linear deflection: any push from any angle will attempt to be
// redirected along the axis that the craft wishes to go (forward)
// i.e. a car will want to go in the direction its wheels are facing
// time till craft moves in direction of outside push
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.06);
// the time it takes to reach top speed min = 0.06
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 2.0);
// time during which the motor's effectiveness exponentially decays max = 120
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 1.0);
// the time it takes to be spinning at full speed. min = 0.06
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.06);
// time during which the spin exponentially decays max = 120
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 120);
// linear friction: friction on a straight line x,y,z planes.
// or how long it will take to stop moving on each axis
// (not a measure of time as far as i can tell).
// higher numbers give less friction. max value = 1000 Default: <1000.0, 2.0, 1000.0>
llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000.0, 2.0, 2.0>);
// angular friction: resistance to turning
// or how easy it is to twist, and how long it will take to level off
// (not a measure of time as far as i can tell).
// higher numbers give less friction. max value = 1000 Default: <10.0, 10.0, 1000.0>
llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <1000.0, 10.0, 1000.0>);
// min = 0.0 = wobbly max = 1.0 = steady
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.50);
// vertical attraction: keeps the top side up
// higher numbers = more degree of bank
// lower numbers = less degree of bank
// i.e. the x axis of the craft is locked to the world x axis
// set above 300 to disable
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.45);
// * Note that by default the vertical attractor will prevent the craft
// * from diving and climbing. So, if you wanted to make a airplane you
// * would probably want to set the VEHICLE_FLAG_LIMIT_ROLL_ONLY flag
// * to allow pitch (nose up/down)
// amount of lean during turns
// min = -1 lean out of turns max = 1 lean into turns (Default: 1)
llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 1);
// time to reach the full tilt of the banking
llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.00);
// min = 0 = static max = 1 = dynamic
// i have no clear idea what this does, in some way it effects
// the craft banking while stopped and moving
llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 1) ;
}
changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
if (agent != llGetOwner())
{
llSay(0, "You aren't the owner");
llUnSit(agent);
llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
}
else
{
llSetStatus(STATUS_PHYSICS, TRUE);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
}
else
{
llSetStatus(STATUS_PHYSICS, FALSE);
llReleaseControls();
llStopAnimation("motorcycle_sit");
}
}
}
run_time_permissions(integer perm)
{
if (perm)
{
llStartAnimation("motorcycle_sit");
llTakeControls(CONTROL_FWD | CONTROL_DOWN | CONTROL_UP | 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 & CONTROL_FWD)
{
//linear motor: as motor implies the push that makes your craft go
// the linear velocity that the craft attempt to achieve. max = 40
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <40,0,0>);
}
if(level & CONTROL_BACK)
{
//linear motor: as motor implies the push that makes your craft go
// the linear velocity that the craft attempt to achieve. max = -40
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <-20,0,0>);
}
// if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
// {
// angular_motor.x += 4*PI;
// angular_motor.z -= 4*PI;
// }
// if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
// {
// angular_motor.x -= 4*PI;
// angular_motor.z += 4*PI;
// }
// if(level & (CONTROL_UP))
// {
// angular_motor.y -= 50;
// }
// if(level & (CONTROL_DOWN))
// {
// angular_motor.y += 50;
// }
// angular velocity (radians/sec) that the vehicle will try to rotate.
// max = 4*PI (2 revolutions/sec)
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <4*PI, 4*PI, 4*PI>);
}
}