Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Friction stops vehicle forever?

OneBigRiver Stork
Diversity matters
Join date: 29 Mar 2006
Posts: 44
12-20-2006 21:26
I expect this is just a n00b question, so please bear with me. :(

I am trying to create a vehicle such that when I push forward, the vehicle starts foward, but eventually slows to a stop on its own. I was hoping to use friction for this. For some reason, however, once my vehicle stops due to friction, it never starts again!

Here is my code ...

CODE

default
{
state_entry()
{
llSetBuoyancy(1.0);
llSetVehicleType(VEHICLE_TYPE_CAR);


llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.1);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 2);
llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <2, 0.1, 0.1> );

//no angular motor
llSetVehicleVectorParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, <1000, 1000, 1000> );
llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 1000 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 120 );

//no angular deflection, all linear deflection
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 10 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 1.0 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 10 );

//vertical attraction
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0 );

//no bank
llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 0 );
llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 1 );
llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 10 );
}

changed(integer change) { // something changed
if (change & CHANGED_LINK) { // and it was a link change
// llSleep(0.5); // llUnSit works better with this delay
key av = llAvatarOnSitTarget();
if (av) { // somebody is sitting on me
llRequestPermissions(av, PERMISSION_TAKE_CONTROLS);
llSetStatus(STATUS_PHYSICS, TRUE);

llOwnerSay("sit");
} else {
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0.0, 0.0, 0.0>);
llSetStatus(STATUS_PHYSICS, FALSE);
}
}
}

run_time_permissions(integer perms)
{
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;

if (pressed & CONTROL_FWD) {
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <5.0, 0.0, 0.0>);
llOwnerSay("fwd");
} else if (pressed & CONTROL_BACK) {
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0.00, 0.0, 0.0>);
llOwnerSay("back");
}
}
}


So I can tell that when I hit forward, my script goes to the right place ... but after my vehicle slows to a stop, re-setting the LINEAR_MOTOR_DIRECTION does not make me go forward again.

I expected friction to just decrase my linear velocity, and not actual stick me to the ground ... what am I missing?

I have also tried using LINEAR_MOTOR_DECAY without using friction, but then my person never seems to stop because there is no friction to slow me down, because my vehicle is buoyant, and lives above the ground...

Basically, this will be a multi-person vehicle that floats along the ground, and people can stand on it. I have it very strongly attracted up, so that the vehicle stays rock-steady as it moves along. What I can't figure out is how to get an "impulse-like" behavior using the linear motor. The vehicle tutorial says this is possible, but I can't figure it out. :(
Geuis Dassin
Filming Path creator
Join date: 3 May 2006
Posts: 565
12-21-2006 07:39
dunno if it helps or not, but you can try llResetScript() after it comes to a complete stop. should reset your script back to its initial state.
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
12-21-2006 08:48
You need a timer to apply the motors in there otherwise when you hit the first button it will do exactly as you said...it will perform properly and then stop completely as it's finished the action you set for it.
Setting the timer will make it constantly reapply the motor settings that your control input changes.
OneBigRiver Stork
Diversity matters
Join date: 29 Mar 2006
Posts: 44
12-21-2006 09:05
From: Tiarnalalon Sismondi
You need a timer to apply the motors in there otherwise when you hit the first button it will do exactly as you said...it will perform properly and then stop completely as it's finished the action you set for it.
Setting the timer will make it constantly reapply the motor settings that your control input changes.


I don't understand. I WANT it to come to a complete stop if the user does not do anything. But, if the user hits the button again, then we should get another push.

Think of it as someone kicking a can. Each kick only takes the can so far: As it moves forward it naturally comes to a stop due to friction. The next time you kick it, it should move forward again.

Or again, think of it as a skateboard where you have to manually push with your foot. Each time you push forward, you are giving one push with your foot. If you stop pushing the vehicle gradually stops.

What I am getting with my vehicle is that the first push works, but the next push doesn't move me! It is as if the friction is so great that I can't get the vehicle moving again.
OneBigRiver Stork
Diversity matters
Join date: 29 Mar 2006
Posts: 44
12-21-2006 09:07
From: Geuis Dassin
dunno if it helps or not, but you can try llResetScript() after it comes to a complete stop. should reset your script back to its initial state.


I thought of that, but this causes other problems with managing the passengers. Plus, I don't think this could possibly be the *right* way to create the behavior I want. :)

I suspect my problem is that I really don't understand what the Linden version of friction is, since it seems pretty clear that it doesn't work like real friction...

Either that, or perhaps I just have some very obvious bug someplace else in my script :P
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
12-21-2006 09:53
If you use llResetScript() you will lose control permissions.

Change it to use VEHICLE_TYPE_AIRPLANE instead of VEHICLE_TYPE_CAR. The car motor needs to be driven from a timer.

Note: You have used llSetBuoyancy(1) to make it float... according to the LSL Wiki Vehicle tutorial (http://lslwiki.com/lslwiki/wakka.php?wakka=TutorialVehicle) this is not recommended, that may also give you problems.

From: someone
It is not recommended that you mix vehicle behavior with some of the other script calls that provide impulse and forces to the object, especially llSetBuoyancy, llSetForce, llSetTorque, and llSetHoverHeight.
OneBigRiver Stork
Diversity matters
Join date: 29 Mar 2006
Posts: 44
12-21-2006 10:17
From: Boss Spectre
If you use llResetScript() you will lose control permissions.

Change it to use VEHICLE_TYPE_AIRPLANE instead of VEHICLE_TYPE_CAR. The car motor needs to be driven from a timer.

Note: You have used llSetBuoyancy(1) to make it float... according to the LSL Wiki Vehicle tutorial (http://lslwiki.com/lslwiki/wakka.php?wakka=TutorialVehicle) this is not recommended, that may also give you problems.


Hurrah! You win! Changing to AIRPLANE worked. Was this actually in the tutorial, and I missed it? :(

Thanks much!

OBR
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
12-21-2006 10:21
Yes it says "VEHICLE_TYPE_CAR Another vehicle that bounces along the ground but needs the motors to be driven from external controls of a timer event."