Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Remote control boat script?

Sanity Karuna
Registered User
Join date: 24 Jun 2004
Posts: 20
08-03-2004 13:02
Hi, I'm not sure if it is possible but how could i change a normal boat script to be remote controlled? Mostly so I don't have to sit on the boat while it moves =)

this is a script I have:

From: someone
default
{
state_entry()
{
llSetSitText("Ride";);
llSitTarget(<0.3, 0.0, 0.3>, ZERO_ROTATION);
llSetCameraEyeOffset(<-5.0, 0.0, 2.0>;);
llSetCameraAtOffset(<3.0, 0.0, 2.0>;);
llSetVehicleType(VEHICLE_TYPE_BOAT);
llSetVehicleFlags(VEHICLE_FLAG_NO_FLY_UP | VEHICLE_FLAG_HOVER_UP_ONLY | VEHICLE_FLAG_HOVER_WATER_ONLY);
// remove these flags
llRemoveVehicleFlags( VEHICLE_FLAG_HOVER_TERRAIN_ONLY
| VEHICLE_FLAG_LIMIT_ROLL_ONLY
| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT);

// least for forward-back, most friction for up-down
llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <2, 3, 2> );

// uniform angular friction (setting it as a scalar rather than a vector)
llSetVehicleFloatParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, 5 );

// linear motor wins after about five seconds, decays after about a minute

llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 5 );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 60 );

// agular motor wins after four seconds, decays in same amount of time

llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 4 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 4 );

// hover
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 0.15);
llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY,.5 );
llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 2.0 );
llSetVehicleFloatParam( VEHICLE_BUOYANCY, 1 );

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

// angular deflection
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.5 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 5 );

// somewhat bounscy vertical attractor
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 5 );

// weak negative damped banking
llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 3 );
llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 0.8 );
llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, .75 );

// 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 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("sit";);
}
}

}

run_time_permissions(integer perm)
{
if (perm)
{
llStartAnimation("sit";);
llTakeControls(CONTROL_FWD | 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)
{
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <20,0,0>;);
}
if(level & CONTROL_BACK)
{
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <-10,0,0>;);
}
if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
{
angular_motor.x += 10;
angular_motor.z -= 10;
}
if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
{
angular_motor.x -= 10;
angular_motor.z += 10;
}
if(level & (CONTROL_UP))
{
angular_motor.y -= 50;
}

llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
}

}


Thank you!
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
08-03-2004 13:29

You need to look at the control(key id, integer level, integer edge) event in your script, that is where user keyboard inputs get translated in to movement.

You need some other way to get control inputs to the script, probably you want your remote control object to llShout commands on some channel. Then when the boat hears the command, to act on it.
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!
Ama Omega
Lost Wanderer
Join date: 11 Dec 2002
Posts: 1,770
08-03-2004 22:14
I think it is easier than that Wednesday. :)

Currently how vehicles work is they ask for permission to take your controls when you sit on them. Sitting on an object grants it some permissions implicitly - meaning you say 'yes' to the script without it ever popping up a dialog.

That is all started in the 'changed' event.

However this isn't required! You can just as easily have it ask in the touch_start event, or by a voice command. In both these cases though a pop-up window will appear to confirm the request.

Once given, then the person can control the vehicle as if they sat on it, even if they don't.

A couple of stickynees items:
1. If you pass TRUE to the 'pass controls' variable of the llTakeControls call then the avatar will move as they control the remote vehicle, thats not good so pass FALSE.

2. Camera is tricky. Pressing any control will swing the camera back to behind the avatar! The trick is a seat with a script that sets the camera position to where they can see the entire track.
_____________________
--
010000010110110101100001001000000100111101101101011001010110011101100001
--
Paradigm Brodsky
Hmmm, How do I set this?
Join date: 28 Apr 2004
Posts: 206
08-05-2004 16:22
Right Ama, I have used that method one experementing with a vehicle. It works like a charm :-)