Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Motorcycle help

Kwipper Manimal
Registered User
Join date: 12 Jan 2005
Posts: 52
05-05-2006 06:10
I am working on a mouselook controlled motorcycle script. It's a modification of the original cory linden script. I am not a good scripter, but I am okay when it comes to modifying scripts.

Basically the motorcycle behaves like this. Just go into mouselook, point in the direction you want to go and the bike will bank and turn in that direction dynamically. The next thing I want to do is to set up the bike so that the faster you go, the less grip you have on the tires, but the slower you go, the more grip you have on the tires. You know. Realistically. Do you have any ideas on how I can do this? I am not a good scripter and I could use help and or script examples.

Anyways. Here is the code.

CODE

//Kwipper's Vehicle Script (Modified from Cory Linden's Vehicle Script)

float forward_max_speed = 20;
float backward_max_speed = 20;
float boost_multiplier = 4; // the number here determines how much of a speed boost you get when you hit the boost
float tire_slippage = 1; //A slider that affects how much the tires will drift on the road making turns. (Higher numbers means more slippage)
float acceleration = 1; // controls the time it takes for the vehicle to accelerate to max speed when you step on the gas.
float deceleration = 10; // controls the time it takes for the vehicle to decelerate to a full stop when you let off the gas.
string sit_message = "Ride"; //The message that appears when you want to ride the vehicle

//Everything below here should only be modified by those experienced in scripting.
default
{
state_entry ()
{
llPassCollisions(TRUE);
llPassTouches(FALSE);
llSetSitText(sit_message);
llSitTarget(<0.6,0.0,0.25>, ZERO_ROTATION);
llSetCameraEyeOffset(<-7.0, 0.0, 1.0>);
llSetCameraAtOffset(<3.0, 0.0, 2.0>);
llSetVehicleType(VEHICLE_TYPE_CAR);
llSetVehicleFlags(VEHICLE_FLAG_CAMERA_DECOUPLED
| VEHICLE_FLAG_LIMIT_MOTOR_UP
| VEHICLE_FLAG_MOUSELOOK_STEER
| VEHICLE_FLAG_MOUSELOOK_BANK
);

llRemoveVehicleFlags( VEHICLE_FLAG_HOVER_WATER_ONLY
| VEHICLE_FLAG_HOVER_TERRAIN_ONLY
| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
);

// least for forward-back, most friction for up-down
llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <100,tire_slippage,1000> );

//I commented this out because it doesn't seem to affect anything with the turning, or anything for that matter
//llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <1000, 1000, 1000>);

// linear motor wins after about 1 second, decays after about a 10 seconds

llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, acceleration );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, deceleration );

// angular motor wins after zero seconds, decays in same amount of time
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,<4*PI,2*PI,0>);
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.06 );
//llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.06 );

// halfway linear deflection with timescale of 3 seconds
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.5 );
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 3 );

// angular deflection with a timescale of 5 seconds
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.5 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 5 );;

llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.3 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.5 );

llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 1 );
llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 0 );

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

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
//if (agent != llGetOwner())
//{
// llSay(0, "You are not the owner of this vehicle. Please step away.");
// llUnSit(agent);
// llPushObject(agent,<0,0,10>, ZERO_VECTOR, FALSE);
//}
//else
{
llSetStatus(STATUS_PHYSICS, TRUE);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
llWhisper(0,"Welcome to Kwipper's Mouselook Motorcycle");
llWhisper(0,"'W' Accelerates, 'S' Decelerates/Reverse.");
llWhisper(0,"'E' Emergency Brake");
llWhisper(0,"'Left Mouse Button' enables turbo boost");
llWhisper(0,"Steer by going into 'Mouselook View' looking in the direction you want to go while accelerating.");
}
}

else
{
integer p = llGetPermissions();
llSetStatus(STATUS_PHYSICS, FALSE);
if(p & PERMISSION_TAKE_CONTROLS)
{
llReleaseControls();
}
if(p & PERMISSION_TRIGGER_ANIMATION)
{
llStopAnimation("motorcycle_sit");
llWhisper(0,"Thank you for trying out Kwipper's Mouselook Motorcycle.");
llWhisper(0,"Let [Kwipper Manimal] know about your experience with this motorcycle");
llPushObject(agent,<0,10,10>, ZERO_VECTOR, FALSE);
}
}
}
}

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

control(key id, integer level, integer edge)
{
if(level & CONTROL_FWD)
{
//A vector. It is the velocity (meters/sec) that the vehicle will try to attain. It points in the vehicle's local frame, and has a maximum length of 40.
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION,<forward_max_speed,0,0>);
}
if(level & CONTROL_BACK)
{
//This sets the max velocity the vehicle will achive by meters/second
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION,<-backward_max_speed,0,0>);
}
if(level & CONTROL_ML_LBUTTON)
{
//This sets the max speed of the turbo
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION,<forward_max_speed*boost_multiplier,0,0>);
}
if(level & CONTROL_UP)
{
//This sets the emergency brake
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION,<0,0,0>);
}
}
}
Kwipper Manimal
Registered User
Join date: 12 Jan 2005
Posts: 52
05-06-2006 03:46
bump
Tip Baker
Registered User
Join date: 12 Nov 2005
Posts: 100
05-06-2006 04:28
What do you want to happen when the tires have less grip?
Kwipper Manimal
Registered User
Join date: 12 Jan 2005
Posts: 52
05-06-2006 04:29
Well. Realistcally when tires have less grip on the road, they have a tendicy to slide more.
Tip Baker
Registered User
Join date: 12 Nov 2005
Posts: 100
05-06-2006 04:45
That sliding breaks down into a number of different effects,

For instance, If you want the acceleration to reduce because the wheels are spinning through lack of grip, you could adjust the VEHICLE_LINEAR_MOTOR_TIMESCALE parameter.

I suggest you have global float called GRIP which holds the percentage of grip that the wheels are providing. It will vary between 0 (No grip) and 1 (full grip)

Youll need a function to constantly check the condition of the bike, speed, bank etc, and then set GRIP. How that function works will depend on how realistic you want to be. At the very least you want the function to read the speed and reduce the grip as the bike speeds up.

You will need a timer to constantly update the grip, and the vehicle parameters according to the amount of grip.

Something like:
CODE
timer()
{
//untested coded
GRIP = GetNewGrip();
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, acceleration * GRIP );
}


Its not something I've looked into, but thats the direction I'd start experimenting with

Hope that helps

Tip