Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Remote Control Vehicle

Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
07-12-2007 02:31
I'm trying to create a remote control vehicle script using a seat to take the avatars controls and camera and transmit controls to the vehicle.

The problem I'm having is that the vehicle only occasionally responds to the controller. It recieves the messages ok when I ask it to tell me but won,t move.

What am I doing wrong?

Also what are integer level and integer edge in the control(key id, integer level, integer edge)?


These are the scripts I'm using

Remote Control Script


[code starts]

//Remote Control Script
//Created by Django Yifu

default
{
state_entry()
{
llSetSitText("Drive";);
llSitTarget(<0.3, 0.0, 0.3>, ZERO_ROTATION);
llSetCameraEyeOffset(<-5.0, 0.0, 10.0>;);
llSetCameraAtOffset(<3.0, 0.0, 2.0>;);
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{

llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
}
else
{
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)
{
llRegionSay(7, "foward";);
}
if(level & CONTROL_BACK)
{
llRegionSay(7, "back";);
}
if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
{
llRegionSay(7, "right";);
}
if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
{
llRegionSay(7, "left";);
}

}

}

[code ends]



The script I'm uding for the vehicle is this



[codde starts]

// Remote control script

//Created by Django Yifu

float forward_power = 10; //Power used to go forward (1 to 30)
float reverse_power = -10; //Power ued to go reverse (-1 to -30)
float turning_ratio = 4.0; //How sharply the vehicle turns. Less is more sharply. (.1 to 10)

default
{
state_entry()
{
//Listens for command from controller
llListen(7,"",NULL_KEY,"";);
llSetStatus(STATUS_PHYSICS, TRUE);

//Vehicle
llSetVehicleType(VEHICLE_TYPE_CAR);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.2);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.80);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.10);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.10);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.2);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.5);
llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000.0, 2.0, 1000.0>;);
llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <10.0, 10.0, 1000.0>;);
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.50);
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.50);
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 2.0 );
llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 1 );
llSetVehicleFloatParam( VEHICLE_BUOYANCY, 1 );

llCollisionSound("", 0.0);
}


listen(integer channel, string name, key id, string message)
{
integer reverse=1;
vector angular_motor;

//get current speed
vector vel = llGetVel();
float speed = llVecMag(vel);


if (message=="foward";) //Listens to foward command
{
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <forward_power,0,0>;);
reverse=1;

}


if(message=="back";) //Listens to back command
{
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <reverse_power,0,0>;);
reverse = -1;

}

if(message=="right";) //Listens to right command
{
angular_motor.z -= speed / turning_ratio * reverse;
}

if(message=="left";) //LIstens to left command
{
angular_motor.z += speed / turning_ratio * reverse;
}


llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
}// end control

}

[code ends]
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
07-12-2007 05:58
Well...I'm just going to put it this way..if you want to use a device as a remote control for a vehicle, you're better off just controlling the vehicle directly (you do not need to be seated on something to have it take your controls, and the way it's handled when you're not sitting on it is no different than when you are)

Using RegionSay to send directional controls, you're going to be subject to sim lag issues to a greater degree than with you just controlling the vehicle directly.


I would instead make it where (if you want the person to sit down to use it) that it RegionSays the ID of the AV to the vehicle, which then requests permissions to take controls.
Django Yifu
Beat Island Gaffer
Join date: 7 May 2007
Posts: 189
07-12-2007 09:23
That's exactly what i've done. I was going in completely the wrong direction with it but had got the basic idea from an original Linden script.

Oh well

:)