Isobeast Posted September 25, 2020 Posted September 25, 2020 (edited) how to make the vehicle perform the following actions while holding down the left mouse button? thanks! control(key name, integer level, integer edge) IN MOUSELOOK: -> left mouse button + turn LEFT - "A"/left arrow key angular.z = 10.0; angular.x = 0.0; -> left mouse button + turn RIGHT - "D"/right arrow key angular.z = -10.0; angular.x = 0.0; Edited September 25, 2020 by Isobeast
Rolig Loon Posted September 25, 2020 Posted September 25, 2020 control(key id, integer level, integer edge) { integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); if ((held & (CONTROL_RIGHT|CONTROL_ROT_RIGHT)) && (llGetAgentInfo(llGetOwner()) & AGENT_MOUSELOOK)) { angular.z = -10.0; angular.x = 0.0; } } ... assuming that you have already used llTakeControls and have obtained PERMISSION_TAKE_CONTROLS. And the same idea for turning left. What you do with that information next depends on whether you are scripting the object as a vehicle or are using some other method. 1
Isobeast Posted September 25, 2020 Author Posted September 25, 2020 18 minutes ago, Rolig Loon said: control(key id, integer level, integer edge) { integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); if ((held & (CONTROL_RIGHT|CONTROL_ROT_RIGHT)) && (llGetAgentInfo(llGetOwner()) & AGENT_MOUSELOOK)) { angular.z = -10.0; angular.x = 0.0; } } ... assuming that you have already used llTakeControls and have obtained PERMISSION_TAKE_CONTROLS. And the same idea for turning left. What you do with that information next depends on whether you are scripting the object as a vehicle or are using some other method. thanks for the reply! Why did I think it would be something like this if (CONTROL_ROT_RIGHT + CONTROL_LBUTTON) { DO STUFF } can it be done like this?
Isobeast Posted September 25, 2020 Author Posted September 25, 2020 I want to add a little to the question. * holding the left mouse button and turning (A/D keys or arrows)
Mollymews Posted September 25, 2020 Posted September 25, 2020 19 minutes ago, Isobeast said: thanks for the reply! Why did I think it would be something like this if (CONTROL_ROT_RIGHT + CONTROL_LBUTTON) { DO STUFF } can it be done like this? if ((held & CONTROL_ROT_RIGHT) && (held & CONTROL_LBUTTON)) { DO STUFF } 1
Rolig Loon Posted September 25, 2020 Posted September 25, 2020 (edited) Oh, wait. I'm sorry. I misread your question. I thought you were testing whether the person is in mouselook, not whether he has clicked the left mouse button. Sorry about that. What you want then is control(key id, integer level, integer edge) { integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); if ((held & (CONTROL_RIGHT|CONTROL_ROT_RIGHT) & ML_LEFT_BUTTON)) { angular.z = -10.0; angular.x = 0.0; } } level is TRUE if you have clicked down on the designated key (CONTROL_RIGHT or CONTROL_ROT_RIGHT) and ~edge is TRUE if you have not released the key. You are doing a bitwise AND of those two values to create a mask to see whether one of those designated keys is the one being held AND whether the left mouse button is also being held. Those are all bitwise operations, so you combine them with bitwise & and | operators. Edited September 25, 2020 by Rolig Loon 1
Xiija Posted September 26, 2020 Posted September 26, 2020 just in case anyone can ever use some pre-defined params... control(key id, integer held, integer chng) { // define params ================== integer start_Fwd = (chng & CONTROL_FWD) && (held & CONTROL_FWD); integer moving_Fwd = (held & CONTROL_FWD); integer release_Fwd = (chng & CONTROL_FWD) && !(held & CONTROL_FWD); integer start_Rev = (chng & CONTROL_BACK) && (held & CONTROL_BACK); integer moving_Rev = (held & CONTROL_BACK); integer release_Rev = (chng & CONTROL_BACK) && !(held & CONTROL_BACK); integer start_Rot_R = (chng & CONTROL_ROT_RIGHT) && (held & CONTROL_ROT_RIGHT); integer Rot_R = (held & CONTROL_ROT_RIGHT); integer release_Rot_R = (chng & CONTROL_ROT_RIGHT) && !(held & CONTROL_ROT_RIGHT); integer start_Slide_R = (chng & CONTROL_RIGHT) && (held & CONTROL_RIGHT); integer Slide_R = (held & CONTROL_RIGHT); integer release_Slide_R = (chng & CONTROL_RIGHT) && !(held & CONTROL_RIGHT); integer start_Rot_L = (chng & CONTROL_ROT_LEFT) && (held & CONTROL_ROT_LEFT); integer Rot_L = (held & CONTROL_ROT_LEFT); integer release_Rot_L = (chng & CONTROL_ROT_LEFT) && !(held & CONTROL_ROT_LEFT); integer start_Slide_L = (chng & CONTROL_LEFT) && (held & CONTROL_LEFT); integer Slide_L = (held & CONTROL_LEFT); integer release_Slide_L = (chng & CONTROL_LEFT) && !(held & CONTROL_LEFT); integer start_Up = (chng & CONTROL_UP) && (held & CONTROL_UP); integer moving_Up = (held & CONTROL_UP); integer release_Up = (chng & CONTROL_UP) && !(held & CONTROL_UP); integer start_Down = (chng & CONTROL_DOWN && held & CONTROL_DOWN); integer moving_Down = (held & CONTROL_DOWN); integer release_Down = (chng & CONTROL_DOWN) && !(held & CONTROL_DOWN); vector angular_motor = ZERO_VECTOR; float speed = llVecMag( llGetVel() ); } 1 1
Isobeast Posted September 26, 2020 Author Posted September 26, 2020 8 minutes ago, Xiija said: just in case anyone can ever use some pre-defined params... control(key id, integer held, integer chng) { // define params ================== integer start_Fwd = (chng & CONTROL_FWD) && (held & CONTROL_FWD); integer moving_Fwd = (held & CONTROL_FWD); integer release_Fwd = (chng & CONTROL_FWD) && !(held & CONTROL_FWD); integer start_Rev = (chng & CONTROL_BACK) && (held & CONTROL_BACK); integer moving_Rev = (held & CONTROL_BACK); integer release_Rev = (chng & CONTROL_BACK) && !(held & CONTROL_BACK); integer start_Rot_R = (chng & CONTROL_ROT_RIGHT) && (held & CONTROL_ROT_RIGHT); integer Rot_R = (held & CONTROL_ROT_RIGHT); integer release_Rot_R = (chng & CONTROL_ROT_RIGHT) && !(held & CONTROL_ROT_RIGHT); integer start_Slide_R = (chng & CONTROL_RIGHT) && (held & CONTROL_RIGHT); integer Slide_R = (held & CONTROL_RIGHT); integer release_Slide_R = (chng & CONTROL_RIGHT) && !(held & CONTROL_RIGHT); integer start_Rot_L = (chng & CONTROL_ROT_LEFT) && (held & CONTROL_ROT_LEFT); integer Rot_L = (held & CONTROL_ROT_LEFT); integer release_Rot_L = (chng & CONTROL_ROT_LEFT) && !(held & CONTROL_ROT_LEFT); integer start_Slide_L = (chng & CONTROL_LEFT) && (held & CONTROL_LEFT); integer Slide_L = (held & CONTROL_LEFT); integer release_Slide_L = (chng & CONTROL_LEFT) && !(held & CONTROL_LEFT); integer start_Up = (chng & CONTROL_UP) && (held & CONTROL_UP); integer moving_Up = (held & CONTROL_UP); integer release_Up = (chng & CONTROL_UP) && !(held & CONTROL_UP); integer start_Down = (chng & CONTROL_DOWN && held & CONTROL_DOWN); integer moving_Down = (held & CONTROL_DOWN); integer release_Down = (chng & CONTROL_DOWN) && !(held & CONTROL_DOWN); vector angular_motor = ZERO_VECTOR; float speed = llVecMag( llGetVel() ); } Thanks! I tried both the recommended versions, but it does not respond to the held mouse button and is not controlled at all in the mouselook... here's what i did. can you have any thoughts on this? run_time_permissions(integer perm) { if(perm & PERMISSION_TAKE_CONTROLS) { llSetStatus(STATUS_PHYSICS|STATUS_BLOCK_GRAB_OBJECT, TRUE); llTakeControls( CONTROL_FWD| CONTROL_BACK| CONTROL_ROT_LEFT| CONTROL_ROT_RIGHT| CONTROL_LEFT| CONTROL_RIGHT| CONTROL_UP| CONTROL_DOWN| CONTROL_LBUTTON| CONTROL_ML_LBUTTON, TRUE, FALSE); llSetTimerEvent(0.5); } } control(key name, integer level, integer edge) ... integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); // non mouselook: if (held & (CONTROL_ROT_LEFT & CONTROL_LBUTTON)) { angular.z = 10.0; } if (held & (CONTROL_ROT_RIGHT & CONTROL_LBUTTON)) { angular.z = -10.0; } // for mouselook: if (held & (CONTROL_ROT_LEFT & CONTROL_ML_LBUTTON)) { angular.z = 10.0; } if (held & (CONTROL_ROT_RIGHT & CONTROL_ML_LBUTTON)) { angular.z = -10.0; }
Isobeast Posted September 26, 2020 Author Posted September 26, 2020 (edited) could it be related to flags? these are the flags I used llRemoveVehicleFlags(-1); llSetVehicleFlags(VEHICLE_FLAG_LIMIT_ROLL_ONLY|VEHICLE_FLAG_CAMERA_DECOUPLED); here is the whole Control event control(key name, integer level, integer edge) { vector linear; vector angular; if(level & CONTROL_FWD) { angular.y += 15.0; } if (level & CONTROL_BACK) { angular.y -= 15.0; } if(level & edge & CONTROL_UP) { if(throttle < 100) { throttle += 10; llOwnerSay("Throttle "+(string)throttle+"%"); } } if(level & edge & CONTROL_DOWN) { if(throttle > 0) { throttle -= 10; llOwnerSay("Throttle "+(string)throttle+"%"); } } if(level & CONTROL_ROT_LEFT) { angular.x = -50.0; } if(level & CONTROL_ROT_RIGHT) { angular.x = 50.0; } integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); if (held & (CONTROL_ROT_LEFT & CONTROL_LBUTTON)) { angular.z = 10.0; } if (held & (CONTROL_ROT_RIGHT & CONTROL_LBUTTON)) { angular.z = -10.0; } if (held & (CONTROL_ROT_LEFT & CONTROL_ML_LBUTTON)) { angular.z = 10.0; } if (held & (CONTROL_ROT_RIGHT & CONTROL_ML_LBUTTON)) { angular.z = -10.0; } if(linear) llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, linear); if(angular) llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular); } Edited September 26, 2020 by Isobeast
Isobeast Posted September 26, 2020 Author Posted September 26, 2020 Here is the whole script vector sitPosition = < 0.00000, 0.00000, 0.50000 > ; vector sitRotation = < 0.00000, 0.00000, 0.00000 > ; vector vehicleRot = < 0.00000, 0.00000, 0.00000 > ; vector camOffset = < -6.00000, 0.00000, 2.00000 > ; float fwd = 20.0; integer throttle; default { state_entry() { llSetStatus(STATUS_PHYSICS, FALSE); llSetVehicleType(1); llSetSitText("Ride..."); llCollisionSound("", 0.0); llSitTarget(sitPosition, llEuler2Rot(sitRotation * DEG_TO_RAD)); rotation rot = llEuler2Rot(vehicleRot * DEG_TO_RAD); llSetCameraAtOffset(-camOffset * rot); llSetCameraEyeOffset(camOffset * rot); llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, rot); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.50); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 10.0); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 1.20); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.60); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 1.00); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.50); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 1.00); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 1.00); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.20); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 2.70); llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.70); llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 1.00); llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 2.00); llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, 0.00); llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.50); llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 1000.0); llSetVehicleFloatParam(VEHICLE_BUOYANCY, 1.00); llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, < 10.0, 10.0, 10.0 > ); llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, < 20.0, 20.0, 20.0 > ); llRemoveVehicleFlags(-1); llSetVehicleFlags(VEHICLE_FLAG_LIMIT_ROLL_ONLY | VEHICLE_FLAG_CAMERA_DECOUPLED); } on_rez(integer start) { llResetScript(); } changed(integer change) { if (change & CHANGED_LINK) { key agent = llAvatarOnSitTarget(); if (agent) { if (agent == llGetOwner()) { llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS); } else { llInstantMessage(agent, "You are not the owner!"); llUnSit(agent); } } else { llResetScript(); } } } run_time_permissions(integer perm) { if (perm & PERMISSION_TAKE_CONTROLS) { llSetStatus(STATUS_PHYSICS | STATUS_BLOCK_GRAB_OBJECT, TRUE); llTakeControls( CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN | CONTROL_LBUTTON | CONTROL_ML_LBUTTON, TRUE, FALSE); llSetTimerEvent(0.5); } } control(key name, integer level, integer edge) { vector linear; vector angular; if (level & CONTROL_FWD) { angular.y += 15.0; } if (level & CONTROL_BACK) { angular.y -= 15.0; } if (level & edge & CONTROL_UP) { if (throttle < 100) { throttle += 10; llOwnerSay("Throttle " + (string) throttle + "%"); } } if (level & edge & CONTROL_DOWN) { if (throttle > 0) { throttle -= 10; llOwnerSay("Throttle " + (string) throttle + "%"); } } if (level & CONTROL_ROT_LEFT) { angular.x = -50.0; angular.z = 0.0; } if (level & CONTROL_ROT_RIGHT) { angular.x = 50.0; angular.z = -0.0; } integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); // Tried both recommended versions here: /* if ((held & (CONTROL_LEFT|CONTROL_ROT_LEFT) & CONTROL_LBUTTON)) { angular.z = 10.0; } if ((held & (CONTROL_RIGHT|CONTROL_ROT_RIGHT) & CONTROL_LBUTTON)) { angular.z = -10.0; }*/ /* if ((held & CONTROL_ROT_RIGHT) && (held & CONTROL_LBUTTON)) { angular.z = -10.0; } if ((held & CONTROL_ROT_LEFT) && (held & CONTROL_LBUTTON)) { angular.z = 10.0; }*/ // My try: if (held & (CONTROL_ROT_LEFT & CONTROL_LBUTTON)) { angular.z = 10.0; } if (held & (CONTROL_ROT_RIGHT & CONTROL_LBUTTON)) { angular.z = -10.0; } if (held & (CONTROL_ROT_LEFT & CONTROL_ML_LBUTTON)) { angular.z = 10.0; } if (held & (CONTROL_ROT_RIGHT & CONTROL_ML_LBUTTON)) { angular.z = -10.0; } if (linear) llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, linear); if (angular) llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular); } timer() { if (throttle) llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, < fwd * (throttle / 100.0), 0, 0 > ); } }
Xiija Posted September 27, 2020 Posted September 27, 2020 (edited) vector linear; vector angular; integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); if( (held & CONTROL_ROT_RIGHT) && (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON) ) { angular.z = -10.0; } // caveat, you cannot touch the vehicle( or anything? ) with the left button when not in mouselook, Edited September 27, 2020 by Xiija 1
Mollymews Posted September 28, 2020 Posted September 28, 2020 Isobeast, I am not sure what you mean by tried both recommended versions and they never worked. One version works and one version doesn't work when both are asked to produce the same result according to the same rule. Which version is working and which version isn't working depends on the rule that we are applying to get the desired result for our particular app say we have 3 bits where: 001 is CONTROL_ROTATE 010 is CONTROL_STRAFE 100 is CONTROL_BUTTON our rule is that any combinations of these return TRUE when the return is greater than 000 given the condition: (held & (CONTROL_ROTATE & CONTROL_BUTTON)) where held is 101. CONTROL_ROTATE held down and CONTROL_BUTTON held down step 1: (CONTROL_ROTATE & CONTROL_BUTTON) = (001 & 100) = (000) step 2: (held & (000)) = (101 & (000)) = (000) = FALSE which is not what we want, for the purpose of our app change condition to: (held & (CONTROL_ROTATE | CONTROL_STRAFE)) step 1: (CONTROL_ROTATE | CONTROL_STRAFE) = (001 | 010) = (011) step 2: (held & (011)) = (101 & (011)) = (001) = TRUE this is what we want to take us to the next step in the condition to obtain the desired result for our app trying condition: (held & (CONTROL_ROTATE | CONTROL_STRAFE) & CONTROL_BUTTON) step 3: ((001) & CONTROL_BUTTON) = ((001) & 100) = (000) = FALSE which is not what we want, at least for this our app so change condition to: ((held & (CONTROL_ROTATE | CONTROL_STRAFE)) && (held & CONTROL_BUTTON)) && is the logical operator AND, not a bitwise operator new step 3: (held & CONTROL_BUTTON) = (101 & 100) = (100) = TRUE step 4: ((001) && (100)) = (TRUE) AND (TRUE) = TRUE which is what we want for the purposes of our app if this is clear as mud then suggest googling for tutorials on bitwise and logical operators to help better understand their purposes and how they are applied. Tutorials are typically written by educators who can explain these things far better than I can. Me not being an educator 1
Isobeast Posted September 28, 2020 Author Posted September 28, 2020 13 hours ago, Mollymews said: Isobeast, I am not sure what you mean by tried both recommended versions and they never worked. One version works and one version doesn't work when both are asked to produce the same result according to the same rule. Which version is working and which version isn't working depends on the rule that we are applying to get the desired result for our particular app say we have 3 bits where: 001 is CONTROL_ROTATE 010 is CONTROL_STRAFE 100 is CONTROL_BUTTON our rule is that any combinations of these return TRUE when the return is greater than 000 given the condition: (held & (CONTROL_ROTATE & CONTROL_BUTTON)) where held is 101. CONTROL_ROTATE held down and CONTROL_BUTTON held down step 1: (CONTROL_ROTATE & CONTROL_BUTTON) = (001 & 100) = (000) step 2: (held & (000)) = (101 & (000)) = (000) = FALSE which is not what we want, for the purpose of our app change condition to: (held & (CONTROL_ROTATE | CONTROL_STRAFE)) step 1: (CONTROL_ROTATE | CONTROL_STRAFE) = (001 | 010) = (011) step 2: (held & (011)) = (101 & (011)) = (001) = TRUE this is what we want to take us to the next step in the condition to obtain the desired result for our app trying condition: (held & (CONTROL_ROTATE | CONTROL_STRAFE) & CONTROL_BUTTON) step 3: ((001) & CONTROL_BUTTON) = ((001) & 100) = (000) = FALSE which is not what we want, at least for this our app so change condition to: ((held & (CONTROL_ROTATE | CONTROL_STRAFE)) && (held & CONTROL_BUTTON)) && is the logical operator AND, not a bitwise operator new step 3: (held & CONTROL_BUTTON) = (101 & 100) = (100) = TRUE step 4: ((001) && (100)) = (TRUE) AND (TRUE) = TRUE which is what we want for the purposes of our app if this is clear as mud then suggest googling for tutorials on bitwise and logical operators to help better understand their purposes and how they are applied. Tutorials are typically written by educators who can explain these things far better than I can. Me not being an educator Thanks a lot! I am absolutely sure that from the point of view of mathematics and logic everything is correct here, and no one would have done it better, but script stubbornly refuses to do what I need. I came across such a post where there is a link to a script using a mouse button and came to the conclusion that perhaps everything is not as simple as it seemed to me. maybe the author @animats will bring some clarity, I apologize for unceremoniously dragging you into this topic. I will try to bring a little more clarity to what I expect from the script. I sit on the object. if I hold down the mouse button and rotate ( A / D keys ), there should be movement along the Z axis without tilting along the X-axis (which does not happen - unfortunately, there is a rotation along the X-axis and Z immediately). in mouselook the same thing should happen.
Isobeast Posted September 28, 2020 Author Posted September 28, 2020 (edited) This is the current version: vector sitPosition = < 0.00000, 0.00000, 0.50000 > ; vector sitRotation = < 0.00000, 0.00000, 0.00000 > ; vector vehicleRot = < 0.00000, 0.00000, 0.00000 > ; vector camOffset = < -6.00000, 0.00000, 2.00000 > ; float fwd = 20.0; integer throttle; default { state_entry() { llSetStatus(STATUS_PHYSICS, FALSE); llSetVehicleType(1); llSetSitText("Ride..."); llCollisionSound("", 0.0); llSitTarget(sitPosition, llEuler2Rot(sitRotation * DEG_TO_RAD)); rotation rot = llEuler2Rot(vehicleRot * DEG_TO_RAD); llSetCameraAtOffset(-camOffset * rot); llSetCameraEyeOffset(camOffset * rot); llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, rot); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.50); llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 10.0); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 1.20); llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.60); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 1.00); llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.50); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 1.00); llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 1.00); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.20); llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 2.70); llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.70); llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 1.00); llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 2.00); llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, 0.00); llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.50); llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 1000.0); llSetVehicleFloatParam(VEHICLE_BUOYANCY, 1.00); llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, < 10.0, 10.0, 10.0 > ); llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, < 20.0, 20.0, 20.0 > ); llRemoveVehicleFlags(-1); llSetVehicleFlags(VEHICLE_FLAG_LIMIT_ROLL_ONLY | VEHICLE_FLAG_CAMERA_DECOUPLED); } on_rez(integer start) { llResetScript(); } changed(integer change) { if (change & CHANGED_LINK) { key agent = llAvatarOnSitTarget(); if (agent) { if (agent == llGetOwner()) { llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS); } else { llInstantMessage(agent, "You are not the owner!"); llUnSit(agent); } } else { llResetScript(); } } } run_time_permissions(integer perm) { if (perm & PERMISSION_TAKE_CONTROLS) { llSetStatus(STATUS_PHYSICS | STATUS_BLOCK_GRAB_OBJECT, TRUE); llTakeControls( CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN | CONTROL_LBUTTON | CONTROL_ML_LBUTTON, TRUE, FALSE); llSetTimerEvent(0.5); } } control(key name, integer level, integer edge) { vector linear; vector angular; if (level & CONTROL_FWD) { angular.y += 15.0; } if (level & CONTROL_BACK) { angular.y -= 15.0; } if (level & edge & CONTROL_UP) { if (throttle < 100) { throttle += 10; llOwnerSay("Throttle " + (string) throttle + "%"); } } if (level & edge & CONTROL_DOWN) { if (throttle > 0) { throttle -= 10; llOwnerSay("Throttle " + (string) throttle + "%"); } } if (level & CONTROL_ROT_LEFT) { angular.x = -50.0; angular.z = 0.0; } if (level & CONTROL_ROT_RIGHT) { angular.x = 50.0; angular.z = -0.0; } integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); if ((held & CONTROL_ROT_RIGHT) && (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON)) { angular.z = 10.0; } if ((held & CONTROL_ROT_LEFT) && (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON)) { angular.z = -10.0; } if (linear) llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, linear); if (angular) llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular); } timer() { if (throttle) llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, < fwd * (throttle / 100.0), 0, 0 > ); } } Edited September 28, 2020 by Isobeast
Wulfie Reanimator Posted September 28, 2020 Posted September 28, 2020 (edited) 5 hours ago, Isobeast said: I am absolutely sure that from the point of view of mathematics and logic everything is correct here, and no one would have done it better, but script stubbornly refuses to do what I need. Computers are stupid. They'll do exactly what you tell them to, but that's not what we want. They should just calculate the right thing instead. 5 hours ago, Isobeast said: I will try to bring a little more clarity to what I expect from the script. I sit on the object. if I hold down the mouse button and rotate ( A / D keys ), there should be movement along the Z axis without tilting along the X-axis (which does not happen - unfortunately, there is a rotation along the X-axis and Z immediately). in mouselook the same thing should happen. Your current script isn't far off. In fact, it is correct. But you're doing both things instead of one or the other. On line 123...132 you have this code: if (level & CONTROL_ROT_LEFT) { angular.x = -50.0; angular.z = 0.0; } if (level & CONTROL_ROT_RIGHT) { angular.x = 50.0; angular.z = -0.0; } And on line 140...149 you have this code: if ((held & CONTROL_ROT_RIGHT) && (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON)) { angular.z = 10.0; } if ((held & CONTROL_ROT_LEFT) && (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON)) { angular.z = -10.0; } So, whenever CONTROL_ROT_* keys are pressed, you will first apply angular X motion (first part), then angular Z motion (second part). You need some way to tell the script that only one of these things should happen, or in this case, you want to make the first part have an additional condition that cannot be fulfilled at the same time as the second part. (They should be mutually exclusive.) The second part -- which is correct -- is supposed to trigger only when CONTROL_LBUTTON or CONTROL_ML_LBUTTON is held. So the first part should trigger only when those buttons are not held. !( (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON) ) We already have the two button-held checks. We'll just put parentheses around the whole thing (the result will be 1 or 0), then apply the "logical Not" operator ("!") to it. It changes a zero to one, and any nonzero back to zero. Basically it just inverts the meaning of whatever condition it's applied to. "If A or B" becomes "if A nor B". So the second part stays the same, but the first part becomes: if (level & CONTROL_ROT_LEFT && !((held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON))) { angular.x = -50.0; angular.z = 0.0; } if (level & CONTROL_ROT_RIGHT && !((held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON))) { angular.x = 50.0; angular.z = -0.0; } This is becoming pretty hard to read (and repetitive) though, so I would recommend making a few variables for convenience. integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); integer LButton = (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON); integer Left = (held & CONTROL_ROT_LEFT) || (held & CONTROL_LEFT); integer Right = (held & CONTROL_ROT_RIGHT) || (held & CONTROL_RIGHT); if (Left && !LButton) { angular.x = -50.0; angular.z = 0.0; } if (Right && !LButton) { angular.x = 50.0; angular.z = -0.0; } if (Right && LButton) { angular.z = 10.0; } if (Left && LButton) { angular.z = -10.0; } Or if you want to get really clever, all of those conditions can be reduced down to... if (Left) { angular.x = -50.0 * (!LButton); angular.z = 10.0 * (LButton); } if (Right) { angular.x = 50.0 * (!LButton); angular.z = -10.0 * (LButton); } Can you guess how that works? Edited September 28, 2020 by Wulfie Reanimator 1 1
Isobeast Posted September 29, 2020 Author Posted September 29, 2020 19 hours ago, Wulfie Reanimator said: Computers are stupid. They'll do exactly what you tell them to, but that's not what we want. They should just calculate the right thing instead. Your current script isn't far off. In fact, it is correct. But you're doing both things instead of one or the other. On line 123...132 you have this code: if (level & CONTROL_ROT_LEFT) { angular.x = -50.0; angular.z = 0.0; } if (level & CONTROL_ROT_RIGHT) { angular.x = 50.0; angular.z = -0.0; } And on line 140...149 you have this code: if ((held & CONTROL_ROT_RIGHT) && (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON)) { angular.z = 10.0; } if ((held & CONTROL_ROT_LEFT) && (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON)) { angular.z = -10.0; } So, whenever CONTROL_ROT_* keys are pressed, you will first apply angular X motion (first part), then angular Z motion (second part). You need some way to tell the script that only one of these things should happen, or in this case, you want to make the first part have an additional condition that cannot be fulfilled at the same time as the second part. (They should be mutually exclusive.) The second part -- which is correct -- is supposed to trigger only when CONTROL_LBUTTON or CONTROL_ML_LBUTTON is held. So the first part should trigger only when those buttons are not held. !( (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON) ) We already have the two button-held checks. We'll just put parentheses around the whole thing (the result will be 1 or 0), then apply the "logical Not" operator ("!") to it. It changes a zero to one, and any nonzero back to zero. Basically it just inverts the meaning of whatever condition it's applied to. "If A or B" becomes "if A nor B". So the second part stays the same, but the first part becomes: if (level & CONTROL_ROT_LEFT && !((held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON))) { angular.x = -50.0; angular.z = 0.0; } if (level & CONTROL_ROT_RIGHT && !((held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON))) { angular.x = 50.0; angular.z = -0.0; } This is becoming pretty hard to read (and repetitive) though, so I would recommend making a few variables for convenience. integer start = level & edge; integer end = ~level & edge; integer held = level & ~edge; integer untouched = ~(level | edge); integer LButton = (held & CONTROL_LBUTTON) || (held & CONTROL_ML_LBUTTON); integer Left = (held & CONTROL_ROT_LEFT) || (held & CONTROL_LEFT); integer Right = (held & CONTROL_ROT_RIGHT) || (held & CONTROL_RIGHT); if (Left && !LButton) { angular.x = -50.0; angular.z = 0.0; } if (Right && !LButton) { angular.x = 50.0; angular.z = -0.0; } if (Right && LButton) { angular.z = 10.0; } if (Left && LButton) { angular.z = -10.0; } Or if you want to get really clever, all of those conditions can be reduced down to... if (Left) { angular.x = -50.0 * (!LButton); angular.z = 10.0 * (LButton); } if (Right) { angular.x = 50.0 * (!LButton); angular.z = -10.0 * (LButton); } Can you guess how that works? Thanks a lot! finally the script works as it should! however, a slight modification had to be made. the first part worked just fine, but there were some difficulties with the mouselook. I began to sort out various combinations of what you all advised me and quite accidentally decided to try using CONTROL_LEFT/RIGHT instead of CONTROL_ROT_LEFT/RIGHT for mouselook. and behold !! Mouselook works ! my joy has no boundaries! Thank you very much to all of you, without you I wouldn't have succeeded! here are the names of these heroes in order of appearance: @Rolig Loon @Mollymews @Xiija @Wulfie Reanimator if (level & CONTROL_ROT_LEFT && !(held & CONTROL_LBUTTON)) { angular.x = -50.0; } if (level & CONTROL_ROT_RIGHT && !(held & CONTROL_LBUTTON)) { angular.x = 50.0; } if ((level & CONTROL_ROT_LEFT) && (held & CONTROL_LBUTTON)) { angular.z = 10.0; } if ((level & CONTROL_ROT_RIGHT) && (held & CONTROL_LBUTTON)) { angular.z = -10.0; } // mouselook: if ((level & CONTROL_LEFT) && (held & CONTROL_ML_LBUTTON)) { angular.z = 50.0; } if ((level & CONTROL_RIGHT) && (held & CONTROL_ML_LBUTTON)) { angular.z = -50.0; } if (level & CONTROL_LEFT) { angular.x = -50.0; } if (level & CONTROL_RIGHT) { angular.x = 50.0; } 1
Recommended Posts
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