Jump to content

Yaw to Cubey Terra's Plane script


Sunbleached
 Share

You are about to reply to a thread that has been inactive for 1595 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello! How to add YAW to Cubey Terra's Plane Airplane script?

I got this wonderful control section but no idea on how this could be done.

And the most important thing: yaw should be done with the Shift or LMB held and turn.

    //FLIGHT CONTROLS     
    control(key id, integer level, integer edge) 
    {
 
            integer throttle_up = CONTROL_UP;
            integer throttle_down = CONTROL_DOWN;
            integer yoke_fwd = CONTROL_FWD;
            integer yoke_back = CONTROL_BACK;
 
            vector angular_motor; 
             
             
            // THROTTLE CONTROL--------------
            if (level & throttle_up) 
            {
                if (fwd < maxThrottle)
                {
                    fwd += 1;
                }
            }
            else if (level & throttle_down) 
            {
                if (fwd > 0)
                {
                    fwd -= 1;
                }
            }
             
            if (fwd != fwdLast)
            {
                llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <(fwd * thrustMultiplier),0,0>);
                 
                // calculate percent of max throttle and send to child prims as link message
                float thrustPercent = (((float)fwd/(float)maxThrottle) * 100);
                llMessageLinked(LINK_SET, (integer)thrustPercent, "throttle", "");
                llOwnerSay("Throttle at "+(string)((integer)thrustPercent)+"%");
                 
                fwdLast = fwd;
                llSleep(0.15); // crappy kludge :P
            }
 
             
            // PITCH CONTROL ----------------
            if (level & yoke_fwd) 
            {
                angular_motor.y = 3.0;
            }
            else if (level & yoke_back) 
            {
                angular_motor.y = -3.0;
            }
            else
            {
                angular_motor.y = 0;
            }
             
 
            // BANKING CONTROL----------------
 
            if ((level & CONTROL_RIGHT) || (level & CONTROL_ROT_RIGHT)) 
            {
                angular_motor.x = TWO_PI;
            }   
            else if ((level & CONTROL_LEFT) || (level & CONTROL_ROT_LEFT)) 
            {
                angular_motor.x = -TWO_PI;
            }
            else
            {
                angular_motor.x = 0;
            }
 
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
             
    } 

 

Edited by Sunbleached
Link to comment
Share on other sites

split out CONTROL_LEFT / CONTROL_RIGHT to apply angular_motor.z

example:

if (level & CONTROL_ROT_RIGHT)  // LeftArrow key
{
   angular_motor.x = TWO_PI;
}
else if (level & CONTROL_ROT_LEFT)  // RightArrow key
{
   angular_motor.x = -TWO_PI;
} 
else
{
   angular_motor.x = 0;
}

if (level & CONTROL_RIGHT)  // Shift+RightArrow keys
{
   angular_motor.z = TWO_PI;
}
else if (level & CONTROL_LEFT)  // Shift+LeftArrow keys
{
   angular_motor.z = -TWO_PI;
} 
else
{
   angular_motor.z = 0;
}

 

  • Thanks 1
Link to comment
Share on other sites

9 hours ago, Mollymews said:

split out CONTROL_LEFT / CONTROL_RIGHT to apply angular_motor.z

example:


if (level & CONTROL_ROT_RIGHT)  // LeftArrow key
{
   angular_motor.x = TWO_PI;
}
else if (level & CONTROL_ROT_LEFT)  // RightArrow key
{
   angular_motor.x = -TWO_PI;
} 
else
{
   angular_motor.x = 0;
}

if (level & CONTROL_RIGHT)  // Shift+RightArrow keys
{
   angular_motor.z = TWO_PI;
}
else if (level & CONTROL_LEFT)  // Shift+LeftArrow keys
{
   angular_motor.z = -TWO_PI;
} 
else
{
   angular_motor.z = 0;
}

 

Thank you very much! I only had to change

if (level & CONTROL_RIGHT)  // Shift+RightArrow keys
{
   angular_motor.z = TWO_PI;
}
else if (level & CONTROL_LEFT)  // Shift+LeftArrow keys
{
   angular_motor.z = -TWO_PI;
}

But basically it works! HAPPY HOLIDAYS!

Link to comment
Share on other sites

@Mollymews Could you help a little bit more please? I'm working with a modification here and now it is not doing the yaw in the mouselook, only banking.

And I am really confused in lsl operators...

 

        if (level & (CONTROL_ROT_LEFT|CONTROL_LEFT))
        {
            if (mode!=-2 && (level & CONTROL_ROT_LEFT || llGetAgentInfo(owner) & AGENT_MOUSELOOK))
            {
                angular_motor.z = 10.0; 
                angular_motor.x = -50.0;
                llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, ANGULAR_START_TIME*.2);
            }
            else 
            {
                angular_motor.z = 10.0; 
                angular_motor.x = -0.0;
                llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 5);
            }
            
            if (edge & (CONTROL_ROT_LEFT|CONTROL_LEFT)) 
            {
                setRudder(-1);
            }

        }

 

Link to comment
Share on other sites

I suggest enclosing the (llGetAgentInfo () & Mouselook) in parentheses to be certain that the bitwise and is being applied to the right thing.

You might want to try writing out a sentence specifying what are the conditions that dictate when yaw is to be applied so that you can then set up the tests accordingly. At the moment it seems to be

If mode is not -2 AND either (or both)  Control_rot_left pressed OR owner in mouselook

Is that what you intended?

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Profaitchikenz Haiku said:

I suggest enclosing the (llGetAgentInfo () & Mouselook) in parentheses to be certain that the bitwise and is being applied to the right thing.

You might want to try writing out a sentence specifying what are the conditions that dictate when yaw is to be applied so that you can then set up the tests accordingly. At the moment it seems to be

If mode is not -2 AND either (or both)  Control_rot_left pressed OR owner in mouselook

Is that what you intended?

Hello! Thank you for your answer! 

It supposed to be:

1. If mode is not -2 

and (Control_rot_left) or (Control_rot_left in mouselook) pressed then "A".

2. If (mode doesnt matter - for all mods, so nothing here...)

(Control_left) or (Control_left in mouselook) pressed then "B".

Mode -2 is on water here. Thats why i dont need banking at the first sentence.

Edited by Sunbleached
Link to comment
Share on other sites

So as you have described option 1, if mode is not 2 AND control_rot_left , then I can't see why you're also testing for the owner in mouselook? Simply looking for control_rot_left is enough?

 

Is it perhaps the value that has been assigned to mode here that's causing the misbehaviour? I would add some ownerSay's to chat out what mode has been set to before making the test.

Edited by Profaitchikenz Haiku
  • Thanks 1
Link to comment
Share on other sites

4 hours ago, Sunbleached said:

@Mollymews Could you help a little bit more please? I'm working with a modification here and now it is not doing the yaw in the mouselook, only banking.

And I am really confused in lsl operators...

 

on the confusion part

with control event logic then to begin with is best to set up flags for the different action parameters. On the wiki a code snippet shows how to translate control key actions to KeyDown, KeyPress and KeyUp

then write your code in longhand to begin with. Longhand meaning that each action has its own code clause. It helps to understand exactly what needs to happen on each action

when we have our vehicle up and running then we come back and optimise our code, combining actions and clauses where we can. Knowing that if our optimisation effort doesn't work as we thought then we can revert to our longhand code that does work and try another way to optimise

a big stumbling block for new/ish coders is attempting to write optimised code from the outset. And to be fair to the new/newish people much of this is because a lot of publicly accessible scripts, wbich we use as a helpy guide, are optimised in part or in whole

so we think that this is how code should be written. Which is true in the final production. When new/ish is better to not try to write optimised code from the outset. Is far more important to understand and write logic. Then when our code works as intended then look to optimise it afterwards

in time as we grow as coders then thru our understanding and writing of logic, and our subsequent attempts to optimise our logically correct code, then we start to reach the place where we can do both in one go

rewriting/renaming the wiki code snippet and using longhand

control(key id, integer level, integer edge)
{
   integer KeyDown = level & edge;
   integer KeyPress = level & ~edge;
   integer KeyUp = ~level & edge;

   integer MouseLook = llGetAgentInfo(id) & AGENT_MOUSELOOK;

   if (MouseLook)
   {
      if (CONTROL_FWD)
      {
         if (KeyDown)
         { ... }
         else if (KeyPress)
         { ... }
         else if (KeyUp)
         { ... }
      }
      if (CONTROL_LEFT)
      {
         ...
      }
      ...
   }
   else // not mouse look
   {
      if (CONTROL_FWD)
      {
         if (KeyDown)
         { ... }
         else if (KeyPress)
         { ... }
         else if (KeyUp)
         { ... }
      }
      if (CONTROL_LEFT)
      {
         ...    
      }
      ...
   }

   ... set vehicle to angular_motor ...
}

 

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Mollymews said:

on the confusion part

with control event logic then to begin with is best to set up flags for the different action parameters. On the wiki a code snippet shows how to translate control key actions to KeyDown, KeyPress and KeyUp

then write your code in longhand to begin with. Longhand meaning that each action has its own code clause. It helps to understand exactly what needs to happen on each action

when we have our vehicle up and running then we come back and optimise our code, combining actions and clauses where we can. Knowing that if our optimisation effort doesn't work as we thought then we can revert to our longhand code that does work and try another way to optimise

a big stumbling block for new/ish coders is attempting to write optimised code from the outset. And to be fair to the new/newish people much of this is because a lot of publicly accessible scripts, wbich we use as a helpy guide, are optimised in part or in whole

so we think that this is how code should be written.

Thank you, I did everything as you wrote, assigned each key separately for each case - mouselook and non. but now it ...ehhh... it does yaw, but does not do banking, and I returned to where it all began and why this moment was added

            if (mode!=-2 && (level & CONTROL_ROT_LEFT || llGetAgentInfo(owner) & AGENT_MOUSELOOK))
            {
                angular_motor.z = 10.0;
                angular_motor.x = -50.0;
                llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, ANGULAR_START_TIME*.2);
            }

In this case, the script in mouselook does banking, but not yaw since i considered it is preferable. I mean it does eather - eather, not both in mouselook... Maybe i am doing something wrong.

Is there any other way?

For example check if...

4 hours ago, Sunbleached said:

1. If mode is not -2 

and (Control_rot_left) or (Control_rot_left in mouselook) pressed then "A".

2. If (mode doesnt matter - for all mods, so nothing here...)

(Control_left) or (Control_left in mouselook) pressed then "B".

Is this a working option? And if yes (oh please!) it will look like?..

if (mode!=-2 && (level & CONTROL_ROT_LEFT) || ((level & CONTROL_ROT_LEFT) && llGetAgentInfo(owner) & AGENT_MOUSELOOK)) {...}

if ((level & CONTROL_LEFT) || ((level & CONTROL_LEFT) && llGetAgentInfo(owner) & AGENT_MOUSELOOK)) {...}

EDIT: Nope just tried - dont work

Edited by Sunbleached
Link to comment
Share on other sites

Why separate control for mouselook at all? I used to work with a boat scripts and as far as I remember there was no separate ML control.

the problem is that it flies perfectly and does both banking and yawing from a third face view, but there is only one of these things in the ML. maybe the problem is really in the parameters, and not in the control.

this is all very strange...

Link to comment
Share on other sites

I would do away with mouselook for now for simplicity's sake and that way you could concentrate on just the different control options.

You could benefit from drawing up a requirements matrix where you list the different types of behaviour required along one axis and the different control inputs available along the other axis, and start marking at the intersections where input X gives required behaviour Y.

  • Thanks 1
Link to comment
Share on other sites

in longhand this is the logic of your if statements. Is this what you intend to happen

control(key id, integer level, integer edge)
{
   integer KeyDown = level & edge;
   integer KeyPress = level & ~edge;
   integer KeyUp = ~level & edge;

   integer MouseLook = llGetAgentInfo(id);

   if (MouseLook)
   {
      if (KeyPress & CONTROL_ROT_LEFT)
      {
          .. do A ...
      }

      if (KeyPress & CONTROL_LEFT)
      {
          ... do B ...
      }
   }
   
   else // is not mouse look
   {
      if (KeyPress & CONTROL_ROT_LEFT)
      {
          if (mode != -2)
          {
             ... do A ...
          }
          // else if (mode == -2) do nothing
      }

      if (KeyPress & CONTROL_LEFT)
      {
         ... do B ...
      }
   }
}

 

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1595 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...