Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Mouselook flying vehicle troubles

Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-03-2007 18:54
Hi there,

I was wondering how to properly code the script below to Turn Banking Forwards backwards left and right in mouse look and still steer properly out of mouse look.

I Tried adding:
llSetVehicleFlags(VEHICLE_FLAG_MOUSELOOK_BANK
| VEHICLE_FLAG_MOUSELOOK_STEER
| VEHICLE_FLAG_CAMERA_DECOUPLED);

To the Script but it will only turn if I mouselook and hold Right at the same time.

Im stumped. If anyone can Help I would greatly appreciate it.



integer sit = FALSE;
integer listenTrack;
integer brake = TRUE;
integer BEACON_INT = 1440; //# of mins between beacon messages
integer beaconMins; // current # of minutes elapsed since last beacon message

float X_THRUST = 28;
float Z_THRUST = 28;

float xMotor;
float zMotor;

key agent;
key pilot;

vector SIT_POS = <0.0, 0.0, 0.8>;
vector CAM_OFFSET = <-5.0, 0.0, 2.0>;
vector CAM_ANG = <0.0, 0.0, 2.0>;

listenState(integer on) // start/stop listen
{
if (listenTrack)
{
llListenRemove(listenTrack);
listenTrack = 0;
}
if (on) listenTrack = llListen(0, "", pilot, "";);
}

help()
{
llWhisper(0,"O Master of the , you may use these commands to fly me...";);
llWhisper(0," Say START to begin moving.";);
llWhisper(0," Say STOP to stop moving.";);
llWhisper(0," PgUp/PgDn or E/C = hover up/down";);
llWhisper(0," Arrow keys or WASD = forward, back, left, right";);
llWhisper(0," Say HELP to display help.";);
}


default {
state_entry()
{
llSetSitText("Fly";);
llSitTarget(SIT_POS, ZERO_ROTATION);
llSetCameraEyeOffset(CAM_OFFSET);
llSetCameraAtOffset(CAM_ANG);
llCollisionSound("SkidSL",1.0);


//SET VEHICLE PARAMETERS
llSetVehicleType(VEHICLE_TYPE_AIRPLANE);



llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <200, 20, 20> );


// uniform angular friction
llSetVehicleFloatParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, 2 );

// linear motor
llSetVehicleVectorParam( VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 2 );
llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 120 );

// agular motor
llSetVehicleVectorParam( VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0> );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0 );
llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, .4);

// hover
llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 2 );
llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY, 0 );
llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 10000 );
llSetVehicleFloatParam( VEHICLE_BUOYANCY, 0.977 );

// no linear deflection
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0 );
llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 5 );

// no angular deflection
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0);
llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 5);

// no vertical attractor
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 1 );
llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 1 );

// banking



llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 2);
llSetVehicleFloatParam( VEHICLE_BANKING_MIX, .5);
llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 0.01);



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

// remove these flags
llRemoveVehicleFlags( VEHICLE_FLAG_NO_DEFLECTION_UP
| VEHICLE_FLAG_HOVER_WATER_ONLY
| VEHICLE_FLAG_LIMIT_ROLL_ONLY
| VEHICLE_FLAG_HOVER_TERRAIN_ONLY
| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
| VEHICLE_FLAG_HOVER_UP_ONLY
| VEHICLE_FLAG_LIMIT_MOTOR_UP );

}

on_rez(integer num)
{
llSetStatus(STATUS_PHYSICS, FALSE);
pilot = llGetOwner();
llSetTimerEvent(60); // beacon timer for 1 min intervals
}


listen(integer channel, string name, key id, string message)
{
message == llToLower(message);
if (message == "help";)
{
help();
}

if (message == "stop";)
{
brake = TRUE;
llWhisper(0,"We are stopped, O Master. You may say START to resume flight.";);
llSetStatus(STATUS_PHYSICS, FALSE);

}
else if (message == "start";)
{
brake = FALSE;
llWhisper(0,"I hear and obey, O Master. We now begin flight.";);
llSetStatus(STATUS_PHYSICS, TRUE);
}
}


// DETECT AV SITTING/UNSITTING AND GIVE PERMISSIONS
changed(integer change)
{
agent = llAvatarOnSitTarget();
if(change & CHANGED_LINK)
{
if((agent == NULL_KEY) && (sit))
{
//
// Avatar gets off vehicle
//
llSetStatus(STATUS_PHYSICS, FALSE);
llStopAnimation("";);
llMessageLinked(LINK_SET, 0, "unseated", "";);
llStopSound();
llReleaseControls();
sit = FALSE;
listenState(FALSE);
}
else if ((agent != NULL_KEY) && (!sit))
{
//
// Avatar gets on vehicle
//
pilot = llAvatarOnSitTarget();
sit = TRUE;
llRequestPermissions(pilot, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION);
listenState(TRUE);
llWhisper(0," , "+llKey2Name(pilot)+", command me as you will. Should you need assistance, please speak the word HELP.";);
llMessageLinked(LINK_SET, 0, "seated", "";);
}


}
}





//CHECK PERMISSIONS AND TAKE CONTROLS
run_time_permissions(integer perm)
{
if (perm & (PERMISSION_TAKE_CONTROLS))
{

llTakeControls(CONTROL_UP | CONTROL_DOWN | CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);

}
if (perm & PERMISSION_TRIGGER_ANIMATION)
{
// Admittedly, animations are bugged. I'll let you figure it out. :) -CT
llStartAnimation("";);
llSetStatus(STATUS_PHYSICS, TRUE);
llStopAnimation("sit";);
}

}





//FLIGHT CONTROLS
control(key id, integer level, integer edge)
{

vector angular_motor;
integer motor_changed;

if ((level & CONTROL_FWD) || (level & CONTROL_BACK))
{
llMessageLinked(LINK_SET, 666, "moving", NULL_KEY);
if (edge & CONTROL_FWD) xMotor = X_THRUST;

if (edge & CONTROL_BACK) xMotor = -X_THRUST;

}
else
{
xMotor = 0;
llMessageLinked(LINK_SET, 666, "stopped", NULL_KEY);
}


if ((level & CONTROL_UP) || (level & CONTROL_DOWN))
{
if (level & CONTROL_UP)
{
zMotor = Z_THRUST;
}
if (level & CONTROL_DOWN)
{
zMotor = -Z_THRUST;
}

}
else
{
zMotor = 0;

}

llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <xMotor,0,zMotor>;);



if (level & CONTROL_RIGHT) {
angular_motor.x = TWO_PI;
angular_motor.y /= 8;
}
if (level & CONTROL_LEFT) {
angular_motor.x = -TWO_PI;
angular_motor.y /= 8;
}

if (level & CONTROL_ROT_RIGHT) {
angular_motor.x = TWO_PI;
angular_motor.y /= 8;
}

if (level & CONTROL_ROT_LEFT) {
angular_motor.x = -TWO_PI;
angular_motor.y /= 8;
}


llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
}

timer()
{
//This is a beacon. Vehicles that are not keyed to owner will often get stolen.
// To avoid leaving vehicle litter all over the world, this beacon notifies the owner of it's location.
if (beaconMins < BEACON_INT)
{
beaconMins += 1;
}
else
{
beaconMins = 0;
vector pos = llGetPos();
llInstantMessage(llGetOwner(), "O Master, I have been left unattended in "+llGetRegionName()+" "+(string)((integer)pos.x)+", "+(string)((integer)pos.y)+", at an altitude of "+(string)((integer)pos.z)+" meters.";);
}
}
}



Thank you for your time

-Cherry
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-04-2007 16:53
Can Anyone help me with this? I would really appreciate it.

-Cherry Hotaling
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-06-2007 09:18
Can anyone Help with this by any chance?

I would be very greatful!

Thank you
-Cherry Hotaling
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
08-06-2007 12:55
Vehicles are tricky and I would need to test before giving you a definitive answer...but I would look to turning your Vertical Attraction Timescale, and Efficiency down a bit. Make the efficiency be like 0.3 and the timescale be about 3.0. Basically the Efficiency is how hard it's going to try to stay veritcal, and the timescale is how long it's going to take it to do it.

Also, the ANGULAR_MOTOR_DIRECTION, should probably not be set to <0,0,0> - I suck at remembering these things off the top of my head, but I would try changing this as well to something like <2,2,4>.

The control function looks like it's already set to use the arrow keys the same way inside and outside of mouselook, so you need to look in the vehicle settings themselves to find the problem.

Try some of the above and see what happens. With vehicles you really have to play with the numbers till it does what you want, so getting advice is a little trickier. (I've been messing with and tweaking a car script for 2 weeks almost now)
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-07-2007 17:26
hehe all that did was make the vehicle flip quickly and didnt make it move in mouse mode at all.

Is there a piece thats missing to add mouse mode?

Thanks for the reply btw.

EDIT:
I noticed that once I added:

llSetVehicleFlags(VEHICLE_FLAG_MOUSELOOK_STEER | VEHICLE_FLAG_MOUSELOOK_BANK);

to the script it would no longer turn when I pressed A or D and when in mouse mode it still didnt turn. But an odd thing happened. When I held D or A and turned the mouse left or Right the vehicle Actually turned.

My problem is why is it only turning with both the mouse and D or A pressed? Also how do I regain my A and D keys out of mouse look?


Totally perplexed,
Cherry Hotaling
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-13-2007 12:01
Anyone have any ideas?

It would be greatly appreciated.

Thank you
-Cherry Hotaling
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-14-2007 06:16
Anyone have any ideas?

It would be greatly appreciated.

Thank you
-Cherry Hotaling
Jotheph Nemeth
Registered User
Join date: 9 Aug 2007
Posts: 142
08-14-2007 13:05
To go into mouse mode, you have to tell the system you want to use mouselook.

I believe you can automatically go into mouselook when you sit in a vehicle, otherwise you'd have to use take controls to get the mouselook button to appear.

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llTakeControls

http://www.lslwiki.net/lslwiki/wakka.php?wakka=llForceMouselook

Add this to your startup function, and anyone sitting down in the vehicle will go into mouselook mode:

llForceMouselook(true)
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-15-2007 06:05
It isnt a problem of going into mouse mode its the ability to control the vehicle IN mouse mode.

Does anyone know by looking at whats in the vehicle script posted what could be missing that will allow you to control the vehicle purely with mouse look and then when out of mouse mode being able to use the keys?

Thanks
-Cherry Hotaling
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
08-15-2007 06:15
Pick either mouse banking or mouse steering, you can't use both

For either, you have to turn on an angular motor for each involved axis the vehicle to turn or bank. I mean turn it on and leave it on.

Becasue mouse steering/banking needs an angular motor on, it becomes quite a trick to steer with the keyboard when out of mouselook. Worse, if you're decoupling the camera as there is a bug that won't let you decouple the camera after the avatar is seated (though crossing a sim border seems to correct it) so switching back and forth is a serious pain.
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
08-15-2007 09:41
hmm...

but i have some vehicles that work fine in both mouselook and key control. but thinking a bit... those might all be land vehicles.

cherry, see if you have any vehicles you can steer with mouselook. clue might be in there (if the scripts are open source).
_____________________
Why Johnny Can't Rotate:
http://forums.secondlife.com/showthread.php?t=94705
Tiarnalalon Sismondi
Registered User
Join date: 1 Jun 2006
Posts: 402
08-15-2007 10:09
A lot of vehicles have timers to detect if the avatar enters mouselook or not and have separate states with separate vehicle controls. I have a bike that drives both in and out of mouselook, and can fly in and out of mouselook. Others just switch to MOUSELOOK_STEER (or BANK) when you enter mouselook and leave the other flags alone.

The bike I have kinda does both. In bike mode it just switches certain flags if you go into mouselook and switches it back if you leave it. Other than the steering it really drives about the same When flying it switches states if you pop in and out of mouselook, going between a sticky throttle in mouselook to a normal push to go, not to stop outside of mouselook.

Really all depends on what exactly you want to accomplish.
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-16-2007 11:21
So Lets say I want my broom to be mouse look only steering. What would I need to change in the Script above? Also does it bank when mouse steering?

Thank you I think im getting closer to my solution because of your replies.

-Lady Cherry
Cherry Hotaling
Registered User
Join date: 25 Feb 2007
Posts: 86
08-20-2007 07:49
So Lets say I want my broom to be mouse look only steering. What would I need to change in the Script above? Also does it bank when mouse steering?

Thank you I think im getting closer to my solution because of your replies.

-Lady Cherry