Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Simple RC Chopper Script

Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
01-21-2008 13:48
i acculy got tired of getting bugged by people on how to make a RC plane so... since it was a simple make i desided id release a simple version for people to play with, it dosen't have much just the basics like left - right turn banking, as i said it a simple script, there are no sounds or special control

have fun...

CODE

///////////////////////////////////
//Simple RC Chopper Script//
/////By Mrc Homewood///////
/////if used include credit/////
//////////////////////////////////

float speed = 0;
float turn = 0;
float lift = 0;
integer move = FALSE;
integer turning = FALSE;


key avatar;
integer on;

default
{
state_entry()
{
llSay(0,"Preparing Helicopter");
llSetVehicleType(VEHICLE_TYPE_AIRPLANE);
llRemoveVehicleFlags(-1);
llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <1, 2, 1> );
llSetVehicleVectorParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, <0.5,0.5,0.5> );
llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.2 );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.75 );
llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.2 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.3 );
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 0 );
llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY, 0 );
llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 1000 );
llSetVehicleFloatParam( VEHICLE_BUOYANCY, 0.99 );
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 2 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 2 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 2 );
llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 0.7 );
llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 0.5 );
llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 0.2 );
llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
llRemoveVehicleFlags( VEHICLE_FLAG_HOVER_WATER_ONLY
| VEHICLE_FLAG_HOVER_TERRAIN_ONLY
| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
| VEHICLE_FLAG_LIMIT_ROLL_ONLY
| VEHICLE_FLAG_HOVER_UP_ONLY
| VEHICLE_FLAG_LIMIT_MOTOR_UP);

llStopSound();
llCollisionSound("", 0.0);
llSetStatus(STATUS_PHYSICS, FALSE);
llSay(0,"Helicopter is ready to fly");
}

touch_start(integer t)
{
avatar = llDetectedKey(0);
string name=llKey2Name(avatar);
if((avatar == llGetOwner()) && (on == TRUE))
{
llSetStatus(STATUS_PHYSICS, FALSE);
llStopSound();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llReleaseControls();
on = FALSE;
}
else if((avatar == llGetOwner()) && (on == FALSE))
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llRequestPermissions(avatar,PERMISSION_TAKE_CONTROLS);
on = TRUE;
}
}

run_time_permissions(integer perms)
{
if(perms & (PERMISSION_TAKE_CONTROLS))
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
}
else
{
llReleaseControls();
llSetStatus(STATUS_PHYSICS,FALSE);
}
}

control(key id, integer level, integer edge)
{
if (level & CONTROL_FWD)
{
speed = 5; // fwd power
move = TRUE;
}

if (level & CONTROL_BACK)
{
speed = -3; // reverse power
move = TRUE;
}

if (level & CONTROL_UP)
{
lift = 2; // up speed
move = TRUE;
}

if (level & CONTROL_DOWN)
{
lift = -2; // down speed
move = TRUE;
}

if ((level & CONTROL_ROT_RIGHT) || (level & CONTROL_RIGHT))
{
turn = 5; // right turn/bank speed
turning = TRUE;
}

if ((level & CONTROL_ROT_LEFT) || (level & CONTROL_LEFT))
{
turn = -5; // left turn/bank speed
turning = TRUE;
}

if(move)
{
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <speed,0,lift>);
lift = 0;
speed = 0;
move = FALSE;
}

if(turning)
{
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <turn,0,0>);
turn = 0;
turning = FALSE;
}

}

on_rez(integer start_param)
{
llResetScript();
}
}
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Library bump
01-21-2008 14:24
:)
_____________________
i've got nothing. ;)
MCM Villiers
Registered User
Join date: 7 Oct 2007
Posts: 39
Guilty
01-24-2008 14:29
I bugged him for the RC script so I am guilty
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
01-24-2008 18:33
lmao ya your 1 of the atleast 20 that did the last few months :P
MCM Villiers
Registered User
Join date: 7 Oct 2007
Posts: 39
01-25-2008 05:43
comment on the script...I had to redo some of the settings as its a bit touchy
Nadine Neddings
Great Squirrel Prophetess
Join date: 11 Mar 2008
Posts: 33
04-28-2008 14:19
From: MCM Villiers
comment on the script...I had to redo some of the settings as its a bit touchy


Would you care to post the revised settings, or hint as to which were touchy, to your thinking?

Thanks for sharing this script! I'm looking forward to experimenting with it.
_____________________
-----------
The only true path to enlightenment is that of the Great Squirrel.
Crunch Underwood
Mr. Grown up, Go away sir
Join date: 25 Sep 2007
Posts: 624
04-28-2008 14:29
i'm surprised it still works under H4... i'm assuming it does? might have a play with it myself one day

-Crunch
_____________________
----------------------------------------------

So your final Nimbus Score is 8.15, a quite remarkable achievement for a biped. Congratulations Crunch, you should be very proud. :-)
Nadine Neddings
Great Squirrel Prophetess
Join date: 11 Mar 2008
Posts: 33
04-28-2008 17:24
I just tried it, and it says, "ready to fly" but otherwise does not respond at all to any movement commands. Darn.

If anyone knows of any alternate helicopter scripts, I would love to hear it.
_____________________
-----------
The only true path to enlightenment is that of the Great Squirrel.
Nadine Neddings
Great Squirrel Prophetess
Join date: 11 Mar 2008
Posts: 33
04-28-2008 17:26
oh! I guess it does work; I just have to click to first allow input of controls for the avatar. hmmm.

It's very strange though; it acts more like an airplane than a helicopter, in that it doesn't seem to want to hover in one place. Maybe I just need to play with it more.
_____________________
-----------
The only true path to enlightenment is that of the Great Squirrel.
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
04-28-2008 19:49
ill check it out then and post a revision with h4
Crunch Underwood
Mr. Grown up, Go away sir
Join date: 25 Sep 2007
Posts: 624
04-28-2008 20:25
thanks Mrc
_____________________
----------------------------------------------

So your final Nimbus Score is 8.15, a quite remarkable achievement for a biped. Congratulations Crunch, you should be very proud. :-)
Nadine Neddings
Great Squirrel Prophetess
Join date: 11 Mar 2008
Posts: 33
04-29-2008 03:50
Thanks Mrc. It does seem to work, though I'm just trying to figure out which variables I need to tweak, to get it to pitch a little more like a helicopter when moving forward (nose down a bit).

But this is a lovely starting point. Thanks for sharing it!
_____________________
-----------
The only true path to enlightenment is that of the Great Squirrel.
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
04-29-2008 16:02
ya there are alot of tweeking but this was just a basic script im online now ill work on a banking and stuf
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
Updated 4/29/08
04-29-2008 16:33
CODE

///////////////////\\\\\\\\\\\\\\\\
//Updated RC Chopper Script\\
///////By Mrc Homewood\\\\\\\
///////////////////\\\\\\\\\\\\\\\\\

// Rudder/H4 updated (BETA)

vector angular_motor;
float myMass;
float speed = 0;
float turn = 0;
float lift = 0;
float rudder = 0;
integer move = FALSE;
integer turning = FALSE;


key avatar;
integer on;

default
{
state_entry()
{
llSay(0,"Preparing Helicopter");
llSetTimerEvent(.1);
myMass = llGetMass();
llSetVehicleType(VEHICLE_TYPE_AIRPLANE);
llRemoveVehicleFlags(-1);
llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <1, 2, 1> );
llSetVehicleVectorParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, <0.5,0.5,0.5> );
llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.2 );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.75 );
llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.2 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.3 );
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 0 );
llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY, 0 );
llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 1000 );
llSetVehicleFloatParam( VEHICLE_BUOYANCY, 0.99 );
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 2 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 2 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 2 );
llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 0.7 );
llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 0.5 );
llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 0.2 );
llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
llRemoveVehicleFlags( VEHICLE_FLAG_HOVER_WATER_ONLY
| VEHICLE_FLAG_HOVER_TERRAIN_ONLY
| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
| VEHICLE_FLAG_LIMIT_ROLL_ONLY
| VEHICLE_FLAG_HOVER_UP_ONLY
| VEHICLE_FLAG_LIMIT_MOTOR_UP);

llStopSound();
llCollisionSound("", 0.0);
llSetStatus(STATUS_PHYSICS, FALSE);
llSay(0,"Helicopter is ready to fly");
}

touch_start(integer t)
{
avatar = llDetectedKey(0);
string name=llKey2Name(avatar);
if((avatar == llGetOwner()) && (on == TRUE))
{
llSetStatus(STATUS_PHYSICS, FALSE);
llStopSound();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llReleaseControls();
on = FALSE;
}
else if((avatar == llGetOwner()) && (on == FALSE))
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llRequestPermissions(avatar,PERMISSION_TAKE_CONTROLS);
on = TRUE;
}
}

run_time_permissions(integer perms)
{
if(perms & (PERMISSION_TAKE_CONTROLS))
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
llSetStatus(STATUS_PHYSICS, TRUE);
}
else
{
llReleaseControls();
llSetStatus(STATUS_PHYSICS,FALSE);
}
}

control(key id, integer level, integer edge)
{
if (level & CONTROL_FWD)
{
angular_motor.y = .5; // front tilt
speed = 2; // fwd power
move = TRUE;
}

if (level & CONTROL_BACK)
{
angular_motor.y = -.2;//back tilt
speed = -.9; // reverse power
move = TRUE;
}

if (level & CONTROL_UP)
{
lift = .8; // up speed
move = TRUE;
}

if (level & CONTROL_DOWN)
{
lift = -.6; // down speed
move = TRUE;
}

if ((level & CONTROL_ROT_RIGHT) || (level & CONTROL_RIGHT))
{
turn = 5; // right turn/bank speed
rudder = -.1;
turning = TRUE;
}

if ((level & CONTROL_ROT_LEFT) || (level & CONTROL_LEFT))
{
turn = -5; // left turn/bank speed
rudder = .1;
turning = TRUE;
}

if(move)
{
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <speed,0,lift>);
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
angular_motor.y = 0;
lift = 0;
speed = 0;
move = FALSE;
}

if(turning)
{
if(speed < 1)
{
llApplyRotationalImpulse(<0,0,rudder> * myMass, TRUE);
turn = 0;
rudder = 0;
turning = FALSE;
}
else
{
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <turn,0,0>);
turn = 0;
turning = FALSE;
}
}

}
timer()
{
integer speed = (integer)(llVecMag(llGetVel()) * 1.94384449 + 0.5);
}
on_rez(integer start_param)
{
llResetScript();
}
}


try that out now i screwed around with a rudder option this is only the beta version for testing feel free to add to it and fix little physics issues that may pop up

threw it together pruty fast so there is bound to be some random stuff xD
Nadine Neddings
Great Squirrel Prophetess
Join date: 11 Mar 2008
Posts: 33
04-29-2008 17:40
Thanks for the update. I noticed a few new quirks off-hand:

1) I'm using your script to create a craft I can pilot directly, traditionally (i.e. sitting in the cockpit). However, with the new update, I'm no longer able to sit in the pilot's seat (it's still the root prim, yes). With the previous version, I can still sit on the seat though.

2) when moving either left, right, forward, or backwards, the craft will begin to gently lose altitude even without touching any controls. A single tap of the page up key will "lock" the craft back into a hover position.

I hope this helps in your bug-smashing process. If I knew more about scripting, I'd help find the source of the bug, but I regret I'm only good for testing after the fact. :/
_____________________
-----------
The only true path to enlightenment is that of the Great Squirrel.
Infrared Wind
Gridologist
Join date: 7 Jan 2007
Posts: 662
04-29-2008 23:46
Hey Mrc --

I'm curious about the addition of the timer and the speed bit.

Thanks for the script! I've had tons of fun with the first version.

Infrared
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
05-01-2008 13:09
the addiation of the speed is acculy part of the rudder system there are a bunch of tiny little fixes and addiations i did,

Example:

if you hover the chopper (speed between 0 - 1) and turn left or right it will use a impules the chopper to turn in rotation

if you are moving forward above speed of 1 and turn it will alow the chopper to bank when it turns, it also allows the chopper to lean forward or back to give it more realism

New Bugs:

forward above 1 = lose/gaining alt
turning very fast = lose/gain alt

ill create a new topic tonight to discuese all the bugs and releases there
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
05-01-2008 13:12
From: someone

1) I'm using your script to create a craft I can pilot directly, traditionally (i.e. sitting in the cockpit). However, with the new update, I'm no longer able to sit in the pilot's seat (it's still the root prim, yes). With the previous version, I can still sit on the seat though.



try deleting your seating script and replacing it, other than that im not sure
Nadine Neddings
Great Squirrel Prophetess
Join date: 11 Mar 2008
Posts: 33
05-06-2008 15:43
From: Mrc Homewood

ill create a new topic tonight to discuese all the bugs and releases there


I've been unable to find the new topic, with the newly-revised script. Does it exist?

Thanks. :)
_____________________
-----------
The only true path to enlightenment is that of the Great Squirrel.
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
05-06-2008 15:56
/54/27/256522/1.html

whent to 5th page, havent did to much to script latly been finishing up my combat system
Nadine Neddings
Great Squirrel Prophetess
Join date: 11 Mar 2008
Posts: 33
05-06-2008 18:14
Thanks!

And ooh, new combat system? I'll be curious to learn about that. :)
_____________________
-----------
The only true path to enlightenment is that of the Great Squirrel.
Jim Perhaps
Registered User
Join date: 10 Dec 2005
Posts: 65
Two suggestion
05-07-2008 08:40
First thank you for this script. Is great fun.

Two things maybe you could add to it. Make it go side to side. think they call it STRAFE using shift and cursor keys. And the other thing make it so the camera stays focused on it.


That would make an already great script outrageous!
Nadine Neddings
Great Squirrel Prophetess
Join date: 11 Mar 2008
Posts: 33
05-07-2008 08:43
Strafing would be great, especially for "parallel parking" in a tight hangar.

Also, I noticed that you cannot turn while holding down your accelerator, so to speak. You have to take your finger off of the forward key, in order to turn left or right. There is momentum to carry the craft forward slightly, to be sure, but it slows down rapidly and creates a disadvantage were this used in combat (which is what I plan to build mine for).
_____________________
-----------
The only true path to enlightenment is that of the Great Squirrel.
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
05-07-2008 12:55
strafing ive been working on ofr another script havent had much luck trying to figure out how it all works
Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
05-07-2008 12:56
From: Nadine Neddings

And ooh, new combat system? I'll be curious to learn about that. :)



ill be realeasing a beta version maybe this weekend or sometime next week in Lestern City (rp group / almost 1/2 sim)
1 2