/// <summary> /// /// </summary> void PositionControl() { //When car is not controlled by us, send information from server if (!view.isMine) { JetController.Move(roll, pitch, m_Yaw, m_Throttle, m_AirBrakes); } else//When car is our the update information { if (InCar) { roll = JetController.RollInput; pitch = JetController.PitchInput; m_AirBrakes = JetController.AirBrakes; m_Yaw = JetController.YawInput; m_Throttle = JetController.ThrottleInput; } } //Sure to player follow the car position, for avoid teletranportation when exit. if (inMyControl && InCar && LocalInCar) { Player.transform.root.position = this.transform.root.position; Player.transform.root.rotation = this.transform.root.rotation; } else if (inMyControl && !InCar) { JetController.Move(0, 0, 0, 0, false); m_Animator.SetInteger("GearState", 1); } }
// Update is called once per frame void FixedUpdate() { if (Input.GetMouseButtonDown(0)) { Debug.Log(transform.position.y.ToString() + " " + pickUp1Transform.position.y.ToString()); } if (transform.position.y > pickUp1Transform.position.y) { _airplane.Move(0, -(transform.position.y - pickUp1Transform.position.y) / 10000f, 0, 0, false); } if (transform.position.y < pickUp1Transform.position.y) { _airplane.Move(0, (transform.position.y - pickUp1Transform.position.y) / 10000f, 0, 0, false); } }
void FixedUpdate() { float roll = 0; float pitch = 0; if (Input.GetMouseButtonDown(0)) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } else if (!Input.GetMouseButton(0)) { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } throttle += Input.GetAxis("Mouse ScrollWheel") * 100; throttle = Mathf.Clamp(throttle, -1, 1); if (Cursor.lockState == CursorLockMode.Locked) { roll = Input.GetAxis("Mouse X") * mouseSensitivity; pitch = Input.GetAxis("Mouse Y") * mouseSensitivity; } else { roll = Input.GetAxis("Horizontal"); pitch = Input.GetAxis("Vertical"); } aircraft.Move(roll, pitch, 0, throttle, false); }
void FixedUpdate() { // Read input for the pitch, yaw, roll and throttle of the aeroplane. float roll = 0; float pitch = 0; float yaw = 0; float throttle = 1; if (inputmanager) { if (isPlaying) { roll = inputmanager.GetResultLeftRightMinus1To1(); pitch = inputmanager.GetResultUpDownMinus1To1() * -1.0f; yaw = inputmanager.GetResultLeftRightMinus1To1() * yawValueFactor; roll *= rollValueFactor; pitch *= pitchValueFactor; yaw *= yawValueFactor; } } // Pass the input to the aeroplane aeroplane.Move(roll, pitch, yaw, throttle, false); }
void FixedUpdate() { //if (networkView.isMine) // { // Read input for the pitch, yaw, roll and throttle of the aeroplane. //#if CROSS_PLATFORM_INPUT float roll = CrossPlatformInput.GetAxis("ROLL"); float pitch = CrossPlatformInput.GetAxis("PITCH"); float yaw = CrossPlatformInput.GetAxis("YAW"); bool airBrakes = CrossPlatformInput.GetButton("THROTTLE"); /*#else * float roll = Input.GetAxis("Horizontal"); * float pitch = Input.GetAxis("Vertical"); * bool airBrakes = Input.GetButton("Fire1"); * //#endif */ // auto throttle up, or down if braking. float throttle = airBrakes ? -1 : 1; AdjustInputForMobileControls(ref roll, ref pitch, ref throttle); // Pass the input to the aeroplane aeroplane.Move(roll, pitch, yaw, throttle, airBrakes); //} }
void FixedUpdate() { pitchInput = -Input.GetAxis("Vertical"); rollInput = Input.GetAxis("Horizontal"); m_Controller.Move(rollInput, pitchInput, 1, 0.1f, false); }
/// <summary> /// /// </summary> void JetPosition() { if (isPlayerIn) { Input1 = JetScript.RollInput; Input2 = JetScript.PitchInput; AirBreak = JetScript.AirBrakes; Horizontal = JetScript.YawInput; Vertical = JetScript.ThrottleInput; } else if (inMyControl && !LocalInVehicle) { JetScript.Move(0, 0, 0, 0, false); m_Animator.SetInteger("GearState", 1); } else { JetScript.Move(Input1, Input2, Horizontal, Vertical, AirBreak); } }
void FixedUpdate() { // Navigation only kicks of once the plane has taken off if (!_takenOff) { // apply full throttle for takeoff m_Controller.Move(0, 0, 0, 1, false); if (m_Controller.Altitude > m_TakeoffHeight) //&& m_NavAgent.grid.CheckInWorld(transform.position)) //&& m_NavAgent.grid.checkInWorld(transform.position)) { _takenOff = true; // Get the path to follow using path follower PathRequestManager.RequestPath(transform.position + transform.forward * 50 + transform.up * 20, m_NavAgent.target.position, OnPathFound); } } // Clamp the speed to maxSpeed once the plane has taken off // Vector3.ClampMagnitude(m_Rigidbody.velocity, maxVelocity); // StartCoroutine(SteerToAvoidCollisions()); }
void FixedUpdate() { var pitch = Input.GetAxis("Vertical"); var roll = Input.GetAxis("Horizontal"); // ロール, ピッチ, ヨー, スロットル, エアブレーキ controller.Move(roll, pitch, 0, 1, false); if (Input.GetKey(KeyCode.F)) { controller.Move(roll, pitch, 0, 1, true); } else if (Input.GetKey(KeyCode.B)) { controller.Move(roll, pitch, 0, 2, false); } else if (Input.GetKey(KeyCode.N)) { controller.Move(roll, pitch, 0, 3, false); } }
private void FixedUpdate() { // Read input for the pitch, yaw, roll and throttle of the aeroplane. float roll = Input.GetAxis("Mouse X"); float pitch = Input.GetAxis("Mouse Y"); m_AirBrakes = Input.GetButton("Fire1"); m_Yaw = Input.GetAxis("Horizontal") * 5; m_Throttle = Input.GetAxis("Vertical"); #if MOBILE_INPUT AdjustInputForMobileControls(ref roll, ref pitch, ref m_Throttle); #endif // Pass the input to the aeroplane m_Aeroplane.Move(roll, pitch, m_Yaw, m_Throttle, m_AirBrakes); }
private void FixedUpdate() { if (!isAccelation) { Mathf.Clamp(_airplane.MaxSpeed -= 1f, 200, 100); if (_airplane.MaxSpeed < 100) { _airplane.MaxSpeed = 100; isAccelation = true; } } #if UNITY_STANDALONE_WIN //Read input for the pitch, yaw, roll and throttle of the aeroplane. float mousePitch = ControlsPrefs.IsMouseEnabled ? CrossPlatformInputManager.GetAxis("Mouse Y") : 0; float mouseRoll = ControlsPrefs.IsMouseEnabled ? CrossPlatformInputManager.GetAxis("Mouse X") : 0; float roll = ControlsPrefs.IsRollEnabled? CrossPlatformInputManager.GetAxis("Roll") + mouseRoll : 0; //Read inputs. They are clamped in AeroplaneController, so can go out of [-1, 1] here. float pitch = (ControlsPrefs.IsInversePitch ? -1f : 1f) * CrossPlatformInputManager.GetAxis("Pitch"); float yaw = CrossPlatformInputManager.GetAxis("Yaw"); #endif #if UNITY_ANDROID rotateClamp = rightRotateClamp != 0 ? rightRotateClamp : leftRotateClamp; float roll = ControlsPrefs.IsRollEnabled ? rotateClamp : 0; yaw = Input.acceleration.x * 1.5f; float pitch; // float pitch = (ControlsPrefs.IsInversePitch ? -1f : 1f) * (Input.acceleration.y*1.5f); if (PlayerPrefs.GetInt("ReviseDirection") == 0) { pitch = (ControlsPrefs.IsInversePitch ? -1f : 1f) * (Input.acceleration.y * 1.5f); //正向控制 } else { pitch = -(ControlsPrefs.IsInversePitch ? -1f : 1f) * (Input.acceleration.y * 1.5f); //反向控制 } #endif bool airBrakes = CrossPlatformInputManager.GetButton("Brakes"); // auto throttle up, or down if braking. float throttle = airBrakes ? -1 : 1; // Pass the input to the aeroplane _airplane.Move(roll, pitch, yaw, throttle, airBrakes); }
void FixedUpdate() { // Read input for the pitch, yaw, roll and throttle of the aeroplane. float roll = CrossPlatformInput.GetAxis("Mouse X"); float pitch = CrossPlatformInput.GetAxis("Mouse Y"); float yaw = CrossPlatformInput.GetAxis("Horizontal"); float throttle = CrossPlatformInput.GetAxis("Vertical"); AdjustInputForMobileControls(ref roll, ref pitch, ref throttle); // Read input for the air brakes. var airBrakes = CrossPlatformInput.GetButton("Fire1"); // Pass the input to the aeroplane aeroplane.Move(roll, pitch, yaw, throttle, airBrakes); }
private void FixedUpdate() { if (numHands == 2) { handData[0].QueryNormalizedJoint(PXCMHandData.JointType.JOINT_CENTER, out JointData_1); handData[1].QueryNormalizedJoint(PXCMHandData.JointType.JOINT_CENTER, out JointData_2); // Pitch center if (pitchNeutral == 0) { pitchNeutral = JointData_1.positionWorld.z; } //Debug.Log("pitchNeutral = " + pitchNeutral); // Roll float roll = CompareFloats(JointData_1.positionWorld.y, JointData_2.positionWorld.y, 0.04f); //Debug.Log("roll = " + roll); // Yaw float yaw = CompareFloats(JointData_1.positionWorld.z, JointData_2.positionWorld.z, 0.04f) * -1; //Debug.Log("pitch = " + pitch); // Break and Pitch float pitch = 0; bool airBrakes = false; // Break and Pitch are on the same axis "z", so handle them together if (Mathf.Abs(JointData_1.positionWorld.z - JointData_2.positionWorld.z) < 0.03f) { pitch = CompareFloats(pitchNeutral, JointData_2.positionWorld.z, 0.05f) * -1; Debug.Log("pitch = " + pitch); airBrakes = (JointData_1.positionWorld.z < 0.5f) ? false : true; } // Throttle float throttle = airBrakes ? -1 : 1; //Debug.Log(CompareFloats(JointData_1.positionWorld.y, JointData_2.positionWorld.y, 0.03f)); m_Aeroplane.Move(roll, pitch, yaw, throttle, airBrakes); } }
void FixedUpdate() { // Read input for the pitch, yaw, roll and throttle of the aeroplane. #if CROSS_PLATFORM_INPUT float roll = CrossPlatformInput.GetAxis("Horizontal"); float pitch = CrossPlatformInput.GetAxis("Vertical"); bool airBrakes = CrossPlatformInput.GetButton("Fire1"); #else float roll = Input.GetAxis("Horizontal"); float pitch = Input.GetAxis("Vertical"); bool airBrakes = Input.GetButton("Fire1"); #endif // auto throttle up, or down if braking. float throttle = airBrakes ? -1 : 1; AdjustInputForMobileControls(ref roll, ref pitch, ref throttle); // Pass the input to the aeroplane aeroplane.Move(roll, pitch, 0, throttle, airBrakes); }
private void FixedUpdate() { if (!isStarted && Input.GetButton("Accelerator")) { isStarted = true; return; } if (isStarted) { var yow = Input.GetAxis("Horizontal2"); var pitch = Input.GetAxis("Vertical"); var roll = Input.GetAxis("Horizontal"); var airBrakes = Input.GetButton("Brake"); float throttle = airBrakes ? -1 : 1; #if MOBILE_INPUT AdjustInputForMobileControls(ref roll, ref pitch, ref throttle); #endif // ロール, ピッチ, ヨー, スロットル, エアブレーキ m_Aeroplane.Move(roll, pitch, yow, throttle, airBrakes); } }
// fixed update is called in time with the physics system update private void Update() { if (GamePickUpsAmount.aiCurrentTarget == null) { Debug.Log("null"); return; } #region 自动躲避障碍物 if (GamePickUpsAmount.aiCurrentTarget.gameObject.tag == Tags.PickUp) { //向正前方发射射线 distanceTest = new Ray(transform.position, airPlaneFront.transform.position - airPlaneLast.transform.position); //Debug.DrawLine(distanceTest.origin, distanceTest.origin + 1000 * distanceTest.direction); distanceTestHit = new RaycastHit(); Physics.Raycast(distanceTest, out distanceTestHit, 300, 1 << LayerMask.NameToLayer("Obstacle")); //如果前方300单位之内有障碍物,那么选择一个最佳方向 if (distanceTestHit.collider != null) { m_last_Target = GamePickUpsAmount.aiCurrentTarget; isRandomTarget = true; ahead = Vector3.Normalize(airPlaneFront.transform.position - airPlaneLast.transform.position); top = Vector3.Normalize(airPlaneTop.transform.position - transform.position); right = Vector3.Normalize(airPlaneRight.transform.position - transform.position); var eightDirectionTest = new Vector3[8]; eightDirectionTest[0] = ahead + top; eightDirectionTest[1] = ahead + right + top; eightDirectionTest[2] = ahead + right; eightDirectionTest[3] = ahead - top + right; eightDirectionTest[4] = ahead - top; eightDirectionTest[5] = ahead - top - right; eightDirectionTest[6] = ahead - right; eightDirectionTest[7] = ahead + top - right; var oneDirectionRay = new Ray(); var oneDirectionRayHit = new RaycastHit(); var eightDirectionCan = new List <Vector3>(); for (int i = 0; i < 8; i++) { oneDirectionRay = new Ray(transform.position, eightDirectionTest[i]); Physics.Raycast(oneDirectionRay, out oneDirectionRayHit, 900, 1 << LayerMask.NameToLayer("Obstacle")); if (oneDirectionRayHit.collider == null) { eightDirectionCan.Add(eightDirectionTest[i]); } if (eightDirectionCan.Count > 0) { var angleEightDirectionCan = new float[eightDirectionCan.Count]; float minAngle = 1000f; for (int j = 0; j < eightDirectionCan.Count; j++) { angleEightDirectionCan[j] = Vector3.Angle(GamePickUpsAmount.aiCurrentTarget.position - transform.position, eightDirectionCan[j]); if (angleEightDirectionCan[j] < minAngle) { angleEightDirectionCan[j] = minAngle; randomTarget.transform.position = transform.position + eightDirectionCan[j]; GamePickUpsAmount.aiCurrentTarget = randomTarget.transform; } } } } } } if (GamePickUpsAmount.aiCurrentTarget.gameObject.tag == Tags.RandomTarget) { if (isRandomTarget) { Invoke("ReSetTarget", 1.0f); } #region //distanceTest = new Ray(transform.position, m_last_Target.position - transform.localPosition); //distanceTestHit = new RaycastHit(); //Physics.Raycast(distanceTest, out distanceTestHit, 90000, 1 << LayerMask.NameToLayer("Obstacle")); //if (distanceTestHit.collider == null) //{ // GamePickUpsAmount.aiCurrentTarget = m_last_Target; // GamePickUpsAmount.aiCurrentTarget = m_last_Target; //} #endregion } #endregion #region AI自动飞行 if (GamePickUpsAmount.aiCurrentTarget != null) { // make the plane wander from the path, useful for making the AI seem more human, less robotic. Vector3 targetPos = GamePickUpsAmount.aiCurrentTarget.position + transform.right * (Mathf.PerlinNoise(Time.time * m_LateralWanderSpeed, m_RandomPerlin) * 2 - 1) * m_LateralWanderDistance; // adjust the yaw and pitch towards the target Vector3 localTarget = transform.InverseTransformPoint(targetPos); float targetAngleYaw = Mathf.Atan2(localTarget.x, localTarget.z); float targetAnglePitch = -Mathf.Atan2(localTarget.y, localTarget.z); // Set the target for the planes pitch, we check later that this has not passed the maximum threshold targetAnglePitch = Mathf.Clamp(targetAnglePitch, -m_MaxClimbAngle * Mathf.Deg2Rad, m_MaxClimbAngle * Mathf.Deg2Rad); // calculate the difference between current pitch and desired pitch float changePitch = targetAnglePitch - m_AeroplaneController.PitchAngle; // AI always applies gentle forward throttle const float throttleInput = 0.5f; // AI applies elevator control (pitch, rotation around x) to reach the target angle float pitchInput = changePitch * m_PitchSensitivity; // clamp the planes roll float desiredRoll = Mathf.Clamp(targetAngleYaw, -m_MaxRollAngle * Mathf.Deg2Rad, m_MaxRollAngle * Mathf.Deg2Rad); float yawInput = 0; float rollInput = 0; if (!m_TakenOff) { // If the planes altitude is above m_TakeoffHeight we class this as taken off if (m_AeroplaneController.Altitude > m_TakeoffHeight) { m_TakenOff = true; } } else { // now we have taken off to a safe height, we can use the rudder and ailerons to yaw and roll yawInput = targetAngleYaw; rollInput = -(m_AeroplaneController.RollAngle - desiredRoll) * m_RollSensitivity; } // adjust how fast the AI is changing the controls based on the speed. Faster speed = faster on the controls. float currentSpeedEffect = 1 + (m_AeroplaneController.ForwardSpeed * m_SpeedEffect); rollInput *= currentSpeedEffect; pitchInput *= currentSpeedEffect; yawInput *= currentSpeedEffect; // pass the current input to the plane (false = because AI never uses air brakes!) m_AeroplaneController.Move(rollInput, pitchInput, yawInput, throttleInput, false); } else { // no target set, send zeroed input to the planeW m_AeroplaneController.Move(0, 0, 0, 0, false); } #endregion }
// fixed update is called in time with the physics system update void FixedUpdate() { if (target != null) { // make the plane wander from the path, useful for making the AI seem more human, less robotic. Vector3 targetPos = target.position + transform.right * (Mathf.PerlinNoise(Time.time * lateralWanderSpeed, randomPerlin) * 2 - 1) * lateralWanderDistance; // adjust the yaw and pitch towards the target Vector3 localTarget = transform.InverseTransformPoint(targetPos); float targetAngleYaw = Mathf.Atan2(localTarget.x, localTarget.z); float targetAnglePitch = -Mathf.Atan2(localTarget.y, localTarget.z); // Set the target for the planes pitch, we check later that this has not passed the maximum threshold targetAnglePitch = Mathf.Clamp(targetAnglePitch, -maxClimbAngle * Mathf.Deg2Rad, maxClimbAngle * Mathf.Deg2Rad); // calculate the difference between current pitch and desired pitch float changePitch = targetAnglePitch - aeroplaneController.PitchAngle; // AI always applies gentle forward throttle float throttleInput = 0.5f; // AI applies elevator control (pitch, rotation around x) to reach the target angle float pitchInput = changePitch * pitchSensitivity; // clamp the planes roll float desiredRoll = Mathf.Clamp(targetAngleYaw, -maxRollAngle * Mathf.Deg2Rad, maxRollAngle * Mathf.Deg2Rad); float yawInput = 0; float rollInput = 0; if (!takenOff) { // if the plane hasn't taken off don't allow it to roll or yaw, only climb desiredRoll = 0; // If the planes altitude is above takeoffHeight we class this as taken off if (aeroplaneController.Altitude > takeoffHeight) { takenOff = true; } } else { // now we have taken off to a safe height, we can use the rudder and ailerons to yaw and roll yawInput = targetAngleYaw; rollInput = -(aeroplaneController.RollAngle - desiredRoll) * rollSensitivity; } // adjust how fast the AI is changing the controls based on the speed. Faster speed = faster on the controls. float currentSpeedEffect = 1 + (aeroplaneController.ForwardSpeed * speedEffect); rollInput *= currentSpeedEffect; pitchInput *= currentSpeedEffect; yawInput *= currentSpeedEffect; // pass the current input to the plane (false = because AI never uses air brakes!) aeroplaneController.Move(rollInput, pitchInput, yawInput, throttleInput, false); } else { // no target set, send zeroed input to the planeW aeroplaneController.Move(0, 0, 0, 0, false); } }