Jump to content

CONTROL_FWD and CONTROL_BACK (level & edge) issue


RedDaemons
 Share

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

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

Recommended Posts

Hello people,

I ask the help of anyone who can devote a few minutes to help me see a solution .

I 'm developing my own script for helicopters and stopped in this situation . I am applying a smooth motion to lower the nose of the helicopter when we press the key to move forward ( CONTROL_FWD ) and went up the nose of the helicopter again when we press the key to move backward ( CONTROL_BAK ) .

To apply this movement , I am using " llSetVehicleVectorParam " parameter where the RATE variable represents the values of inclination .

llSetVehicleVectorParam ( VEHICLE_ANGULAR_MOTOR_DIRECTION , < 0 , RATE, 0 > ) ;

This is working perfectly when we press the key to move forward (nose lowers ) and keys to move backward (nose rises) .

The problem is when we stop pressing the keys , because I am unable to perform the action of leveling . I need that when you release the keys , the object is again flat at < 0,0,0 > . For this, I am applying again this parameter as follows :

llSetVehicleVectorParam ( VEHICLE_ANGULAR_MOTOR_DIRECTION , < 0 , 0, 0 > ) ;

However, when you release the keys , this parameter ( nor any other command I put ) do not runs.

I've found this post that deals with a similar issue, but was unable to apply the result. In an isolated prism, this post worked, but in my project does not work.
http://community.secondlife.com/t5/LSL-Scripting/Problems-returning-rotating-prims-to-center/td-p/2557486/highlight/true

Where can I be missing for the command ~level & edge; not work in my script?

This is the part of the code I am talking about, Note that is a part of the script. All variables and parameters are already configured in state_entry() and the start of the code. I removed others commands to focus only in the part we are discussing.

control(key id, integer level, integer edge) {

integer PRESSED = level & ~edge;
integer RELEASED = ~level & edge;


if(PRESSED & (CONTROL_FWD)) {
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0,RATE,0>); // Down Nose
}


if(PRESSED & (CONTROL_BACK)) {
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0,-RATE,0>); // Up Nose
}

if (RELEASED & (CONTROL_FWD) || RELEASED & (CONTROL_BACK)){
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0,0,0>); // Should return and nivelate
}

}

Adding: The same procedure, using "VEHICLE_ANGULAR_MOTOR_DIRECTION", is being used to create a slow banking movement with sucess. When I press direcional keys, the helicopter do a bank, to left or right, and returns correctly when I release the keys. So I can figure is not a llSetVehicleVectorParam problem, because it is working in banking process, to left and right, and for down and up the nose. Only do not work in the situation described above, not nivelating the helicopter in axis again.

Thank you in advance.

Link to comment
Share on other sites

I don't generally work with vehicles, so I can only give you an educated guess at a solution.  Take a look at llSetVehicleFloatParam . I suspect that you can get the helicopter to orient itself quickly if you make VEHICLE_VERTICAL_ATTRACTION_TIMESCALE smaller. In the absence of forces that push its Z-axis away from vertical, that change should make the helicopter default to fly level.

I can't guess what "nivelate" means, even after searching on line, so you're on your own with that part of the problem.

  • Like 1
Link to comment
Share on other sites


RedDaemons wrote:

 

llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0,0,0>);


A zero vector won't apply any force the the vehicle motors. ZERO_VECTOR will shut the motors off. So it can't rotate it back into a level position by calling it. You would have to apply a counter force to make it rotate back.

I guess you have set the VEHICLE_FLAG_LIMIT_ROLL_ONLY flag also. That would explain why it levels out when turning left/right by the vertical attractor, but not around the Y (pitch) axis.

Probably, for a helicopter I would remove the VEHICLE_FLAG_LIMIT_ROLL_ONLY flag, and would play with the VEHICLE_REFERENCE_FRAME instead, rather than feeding the motors to adjust the pitch.

Like when the forward key is pressed (note, it's pressed, not holding down, integer pressed = level & edge), changing the reference frame so that the nose will look slightly downwards.

And vice versa when the back key is pressed. And on release, setting the reference frame back to ZERO_ROTATION again.

Like this:

        integer pressed = level & edge;        integer down = level & ~edge;        integer released = ~level & edge;                if (pressed & CONTROL_FWD) {            llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, llEuler2Rot(<0.0, -15.0, 0.0> * DEG_TO_RAD));        }        else if (pressed & CONTROL_BACK) {            llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, llEuler2Rot(<0.0, 15.0, 0.0> * DEG_TO_RAD));        }        if (released &  (CONTROL_FWD|CONTROL_BACK)) {            llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, llEuler2Rot(<0.0, 0.0, 0.0> * DEG_TO_RAD));                          }

 

 

  • Like 1
Link to comment
Share on other sites

Rolig Loon, sorry about "nivelate".. dammit.. it was Google orthographic corrector. I was trying to say put the helicopter back at zero position on axis Y. I will check the tips you sent me.

And arton Rotaru, I understand your explanation. I will check it right now. It I get some progress, I post here again. I will review de method I am using .

Thank you both.

Link to comment
Share on other sites

arton Rotaru is working perfectly ! :matte-motes-grin:

I have disabled the option VEHICLE_FLAG_LIMIT_ROLL_ONLY . I was already using VEHICLE_REFERENCE_FRAME parameter.

But I kept my settings as "integer PRESSED = level & ~ edge" . If I modify as you suggested , I would have to keep pressing and releasing, pressing and releasing to change the values of the cyclic helicopter . And it would not be good. The good is continuously pressing for a more realistic and smooth effect.

There are two main models control helicopter in Second Life . A type of control where you trigger the cyclic ( go forward and back ) and the collective ( up and down ) in increments of 5 % . This model is widely used in helicopters of the biggest manufacturers and is one of the most appreciated by users . But there's another model where the increment is 1% of 1% . This second model control is more smooth and precise. It's like I'm developing my project and that was the reason I kept the PRESSED variable the way I did . Well, there are a third method where you keep pressing all the time, like a motorcycle or car. I do not like this method.

I also made some adjustments from the solution you provided making the helicopter more smooth and precise .

Many thanks to the two arton Rotaru as Rolig Loon . You helped me solve a huge problem and opened my knowledge to new opportunities .

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 3779 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...