Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Vehicle Rotation

Mikemmax Benford
Registered User
Join date: 1 Jun 2006
Posts: 14
08-27-2007 15:44
Hello,

I am working on this Flying Machine and I would like to know how to rotate the machine 360 degrees using home and end buttons, staying in the same spot for turning purposes. Example when object is moving forward I want to be able hit the right button. I want it to start to rotate or start to turn in that direction. If I am staying still I want to be able to hit either end and home to rotate it 360 degrees around, like avatar does when flying and you hit right or left.

Thank You

Mikemmax Benford
Dina Vanalten
Registered User
Join date: 24 Dec 2006
Posts: 268
08-27-2007 18:57
Here are some clues. Hope they help.

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, TRUE);
}
}

control(key id, integer down, integer new)
{
// Set control key values
pressed = down & new;
held = down & ~new;
released = ~down & new;

if (held & CONTROL_ROT_LEFT)
{
vector eul = <0,0, Rotate_Increment>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}

else
if (held & CONTROL_ROT_RIGHT)
{
vector eul = <0,0,-Rotate_Increment>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}
}
Mikemmax Benford
Registered User
Join date: 1 Jun 2006
Posts: 14
Doesn't do anything
08-27-2007 20:54
Hello,

I have tried this for my left and right and it seems that it make it not work at all. I am working with jester Knox's flight script.

<code>
if (held & CONTROL_ROT_LEFT)
{
vector eul = <0,0, 2.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}

else
if (held & CONTROL_ROT_RIGHT)
{
vector eul = <0,0,-2.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}
</code>

I can make it slide right or left, but it doesn't want to rotate to the left or right. I know I am doing something wrong, but don't know what.

Is there a way to make new buttons, say like using home and end?

Any suggestions, Thank You for all you help.

Mikemmax Benford
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
08-27-2007 22:00
You can use CONTROL_ROT_RIGHT and CONTROL_ROT_LEFT for rotating/turning, and CONTROL_LEFT and CONTROL_RIGHT for sliding sideways without rotating. The latter two are available by holding SHIFT while pressing left/right arrows.
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
08-27-2007 22:02
By the way, the Home and End keys are referenced as CONTROL_UP and CONTROL_DOWN, respectively.
Mikemmax Benford
Registered User
Join date: 1 Jun 2006
Posts: 14
Ok have problem
08-27-2007 22:49
From: Boss Spectre
You can use CONTROL_ROT_RIGHT and CONTROL_ROT_LEFT for rotating/turning, and CONTROL_LEFT and CONTROL_RIGHT for sliding sideways without rotating. The latter two are available by holding SHIFT while pressing left/right arrows.


When I try this I get nothing.

<code>
if ( level & (CONTROL_LEFT) )

{
vector eul = <0,0, 2.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}

else if ((edge & ~level & CONTROL_LEFT))
{
vector eul = <0,0, 0.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}


else if ( level & (CONTROL_RIGHT) )

{
vector eul = <0,0,-2.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}

else if ((edge & ~level & CONTROL_RIGHT))
{
vector eul = <0,0,-0.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}
</code>

When I try this I get nothing


<code>
if ( level & (CONTROL_ROT_LEFT) )

{
vector eul = <0,0, 2.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}

else if ((edge & ~level & CONTROL_ROT_LEFT))
{
vector eul = <0,0, 0.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}


else if ( level & (CONTROL_ROT_RIGHT) )

{
vector eul = <0,0,-2.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}

else if ((edge & ~level & CONTROL_ROT_RIGHT))
{
vector eul = <0,0,-0.0>;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot(eul);
llSetRot( llGetRot() * quat );
}
</code>

This makes it Slide

<code>
if ( level & (CONTROL_ROT_LEFT) )

{
linear.z = 2.0 ;
}

else if ((edge & ~level & CONTROL_ROT_LEFT))
{
linear.z = 0 ;
}


else if ( level & (CONTROL_ROT_RIGHT) )

{
linear.z = -2.0 ;
}

else if ((edge & ~level & CONTROL_ROT_RIGHT))
{
linear.z = 0 ;
}
</code>

This doesn't work at all

<code>
if ( level & (CONTROL_LEFT) )

{
linear.z = 2.0 ;
}

else if ((edge & ~level & CONTROL_LEFT))
{
linear.z = 0 ;
}


else if ( level & (CONTROL_RIGHT) )

{
linear.z = -2.0 ;
}

else if ((edge & ~level & CONTROL_RIGHT))
{
linear.z = 0 ;
}
</code>

I still don't understand what I am doing wrong. Wondering if a FLAG could be doing it?

Thank You for that info. Wasn't aware of that.

Thank You for all your help,

Mikemmax Benford
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
08-27-2007 23:42
Ahhh is the object physical? llSetRot is only for non-physical objects.
Mikemmax Benford
Registered User
Join date: 1 Jun 2006
Posts: 14
Ohh
08-27-2007 23:45
From: Boss Spectre
Ahhh is the object physical? llSetRot is only for non-physical objects.


Yes It is. So what would I have to do, either make it non-physical or, is there another way.

Thank You for you help

Mikemmax Benford
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
08-27-2007 23:45
You might look in your script for a vector called something like "angular" which is the rotational equivalent of "linear". (Such names are internal to a given script so I cannot offer a more precise guide) This is where you would create rotation on a physical task.
Mikemmax Benford
Registered User
Join date: 1 Jun 2006
Posts: 14
Ok found it
08-27-2007 23:51
From: Boss Spectre
You might look in your script for a vector called something like "angular" which is the rotational equivalent of "linear". (Such names are internal to a given script so I cannot offer a more precise guide) This is where you would create rotation on a physical task.


I got this:

<code>
// and controls are assuming a flying craft.
llSetVehicleType(VEHICLE_TYPE_AIRPLANE) ;

// linear friction: friction on a straight line x,y,z planes.
// or how long it will take to stop moving on each axis
// (not a measure of time as far as i can tell).
// higher numbers give less friction. max value = 1000
llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <100.0, 100.0, 100.0>;) ;

// angular friction: resistance to turning
// or how easy it is to twist, and how long it will take to level off
// (not a measure of time as far as i can tell).
// higher numbers give less friction. max value = 1000
llSetVehicleFloatParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, 100.0) ;

//linear motor: as motor implies the push that makes your craft go

// the linear velocity that the craft attempt to achieve. max = 40
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <100.0, 100.0, 100.0>;) ;
// the time it takes to reach top speed min = 0.06
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0) ;
// time during which the motor's effectiveness exponentially decays max = 120
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 2.0) ;

// angular motor: motor that twists the path of the craft

// angular velocity (radians/sec) that the vehicle will try to rotate.
// max = 4*PI (2 revolutions/sec)
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <100.0, 100.0, 100.0>;) ;
// the time it takes to be spinning at full speed. min = 0.06
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 1.0) ;
// time during which the spin exponentially decays max = 120
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 2) ;


// time for craft to stabilize at hover height
// **values greater than 300 disable hover**
llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 360.0) ;
// height to hover at. what craft will use as the base height
// to base this from depends on the flags set
// VEHICLE_FLAG_HOVER_WATER_ONLY
//| VEHICLE_FLAG_HOVER_TERRAIN_ONLY
//| VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT
// we will set these (or not) later
llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, 0.0) ;
// min = 0.0 max = 1.0
// 0.0 = bouncey 1.0 = smooth
// how tightly the craft adheres to the hover height
// timescale will be the oscillation period of the bounce.
llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.0) ;
// 0 = normal phsycs apply
// 1 = anti-gravity, the force of gravity will not apply
// -1 = adds extra gravity to craft
llSetVehicleFloatParam(VEHICLE_BUOYANCY, 0.98) ;



// linear deflection: any push from any angle will attempt to be
// redirected along the axis that the craft wishes to go (forward)
// i.e. a car will want to go in the direction its wheels are facing

// time till craft moves in direction of outside push
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 1.0) ;
// no deflection = (0.0) max deflection = 1.0
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.0) ;



// angular deflection: an outside push will attempt to reorient craft
// to match direction of push.
// i.e. a collision from the side will turn the craft to point
// the same direction as the impact was going.

// time till craft twists to match direction of outside push
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 1.0) ;
// no deflection = (0.0) max deflection = 1.0
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.1) ;

</code>

Not sure which one though. Sorry the comments aren't helping me. Tried messing with all
of the above, but nothing.

Thank You,

Mikemmax Benford
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
08-28-2007 01:19
What you're looking for is something like this:

llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular);

which would be near something like this:
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, linear);

probably in a timer event for a hover vehicle.

then in the control event, you'd find the code that sets angular near the code that sets linear, you might check your original version of the script to see if it was removed