Beispiel #1
0
 public void LateUpdate()
 {
     //LocalSpeed = transform.InverseTransformDirection(m_Rigidbody.velocity);
     Speed                  = (this.transform.position - LastPosition) / Time.deltaTime;
     LocalSpeed             = transform.InverseTransformDirection(Speed);
     carController.Skidding = Vector3.Angle(this.transform.forward, Speed) > 2;
     if (ValueAdjust.JudgeRange(Speed.magnitude, LastSpeed, 1f))
     {
         AccelInput = ValueAdjust.Lerp(AccelInput, 0, Time.deltaTime);
         BrakeInput = ValueAdjust.Lerp(BrakeInput, 0, Time.deltaTime);
     }
     else
     {
         if (Speed.magnitude > LastSpeed)
         {
             AccelInput = ValueAdjust.Lerp(AccelInput, 1, Time.deltaTime);
         }
         else
         {
             AccelInput = ValueAdjust.Lerp(AccelInput, 0, Time.deltaTime);
         }
         BrakeInput = ValueAdjust.Lerp(BrakeInput, 1 - AccelInput, Time.deltaTime);
     }
     CalculateRevs();
     carController.Revs = RevsPercent;
     LastPosition       = this.transform.position;
     LastSpeed          = Speed.magnitude;
 }
Beispiel #2
0
 void Update()
 {
     if (Input.GetKey(Key_Left) || Input.GetKey(Key_Right))
     {
         if (Input.GetKey(Key_Left))
         {
             m_SliderX = ValueAdjust.Lerp(m_SliderX, -1, Time.deltaTime);
         }
         else if (Input.GetKey(Key_Right))
         {
             m_SliderX = ValueAdjust.Lerp(m_SliderX, 1, Time.deltaTime);
         }
     }
     else
     {
         m_SliderX = ValueAdjust.Lerp(m_SliderX, 0, Time.deltaTime);
     }
     if (Input.GetKey(Key_Up) || Input.GetKey(Key_Down))
     {
         if (Input.GetKey(Key_Up))
         {
             m_SliderY = ValueAdjust.Lerp(m_SliderY, 1, Time.deltaTime);
         }
         else if (Input.GetKey(Key_Down))
         {
             m_SliderY = ValueAdjust.Lerp(m_SliderY, -1, Time.deltaTime);
         }
     }
     else
     {
         m_SliderY = ValueAdjust.Lerp(m_SliderY, 0, Time.deltaTime);
     }
     if (Input.GetKey(Key_Forward) || Input.GetKey(Key_Back))
     {
         if (Input.GetKey(Key_Forward))
         {
             m_SliderZ = ValueAdjust.Lerp(m_SliderZ, 1, Time.deltaTime);
         }
         else if (Input.GetKey(Key_Back))
         {
             m_SliderZ = ValueAdjust.Lerp(m_SliderZ, -1, Time.deltaTime);
         }
     }
     else
     {
         m_SliderZ = ValueAdjust.Lerp(m_SliderZ, 0, Time.deltaTime);
     }
     if (Input.GetMouseButtonDown(1))
     {
         MousePositon_Start = Input.mousePosition;
     }
     if (Input.GetMouseButton(1) && m_Controller)
     {
         Vector2 MouseOnScreen = new Vector2((Input.mousePosition.x - MousePositon_Start.x) / Screen.width, (Input.mousePosition.y - MousePositon_Start.y) / Screen.height) * 2;
         m_Text[0].text = "Mouse:" + MouseOnScreen;
         //m_Camera.transform.RotateAround(m_Controller.transform.position, Vector3.up, MouseOnScreen.x * Time.deltaTime * 10);
         //m_Camera.transform.RotateAround(m_Controller.transform.position, Vector3.right, MouseOnScreen.y * Time.deltaTime * 10);
     }
 }
Beispiel #3
0
 private void Update()
 {
     //m_Rigidbody.velocity = new Vector3(m_Rigidbody.velocity.x, Mathf.Clamp(m_Rigidbody.velocity.y, -0.05f, 10f), m_Rigidbody.velocity.z).normalized * m_Rigidbody.velocity.magnitude;//限制向下的速度向量
     if (!isTouched)
     {
         if (Quaternion.Angle(HitEffectPos.rotation, this.transform.rotation) < 15 && (HitEffectPos.position - Target.position).magnitude > 0.5f)//初期朝向角度过大时不进行跟踪
         {
             //改变自身朝向
             this.transform.forward = ValueAdjust.Lerp(this.transform.forward, (Target.transform.position - this.transform.position).normalized, Time.deltaTime, (this.transform.forward - (Target.transform.position - this.transform.position).normalized) * 15);
         }
         m_Rigidbody.velocity = this.transform.forward.normalized * (m_Rigidbody.velocity.magnitude + 30 * Time.deltaTime);//改变速度方向为目标方向
     }
 }
Beispiel #4
0
        /// <summary>
        /// 计算转速
        /// </summary>
        private void CalculateRevs()
        {
            float CurrentFactor = 1;
            float wheelRevs;

            //wheelRevs = (carController.m_WheelColliders[0].rpm + carController.m_WheelColliders[1].rpm + carController.m_WheelColliders[2].rpm + carController.m_WheelColliders[3].rpm) / 4;
            wheelRevs = Speed.magnitude * 60f / carController.m_WheelColliders[0].radius;
            if (wheelRevs > WheelRevs && RevsPercent > 0.8f)
            {
                WheelRevs = ValueAdjust.Lerp(WheelRevs, wheelRevs, Time.deltaTime, 200);
            }
            else if (wheelRevs > WheelRevs && RevsPercent > 0.6f)
            {
                WheelRevs = ValueAdjust.Lerp(WheelRevs, wheelRevs, Time.deltaTime, 800);
            }
            else
            {
                WheelRevs = wheelRevs;
            }
            //计算引擎转速(用于显示和声音)
            EngineRevs = WheelRevs * CurrentFactor;
            if (EngineRevs > Revs)
            {
                if (RevsPercent > 0.8f)
                {
                    Revs = ValueAdjust.Lerp(Revs, EngineRevs, Time.deltaTime, 200);
                }
                else if (RevsPercent > 0.6f)
                {
                    Revs = ValueAdjust.Lerp(Revs, EngineRevs, Time.deltaTime, 1000);
                }
                else
                {
                    //Revs = Mathf.Lerp(Revs, EngineRevs, Time.deltaTime * 4f);
                    Revs = ValueAdjust.Lerp(Revs, EngineRevs, Time.deltaTime, 5000);
                }
            }
            else
            {
                Revs = ValueAdjust.Lerp(Revs, 0, Time.deltaTime, 2000);
                //Revs = Mathf.Lerp(Revs, 0, Time.deltaTime * 0.5f);
            }
            Revs        = ValueAdjust.Clamp(Revs, 0, TopRevs);
            RevsPercent = ValueAdjust.Clamp(Revs / TopRevs);
        }
Beispiel #5
0
 private void LateUpdate()
 {
     this.transform.localEulerAngles = new Vector3(ValueAdjust.Lerp(this.transform.localEulerAngles.x, isDie ? 90 : 0, Time.deltaTime, 90), this.transform.localEulerAngles.y, 0);
 }
Beispiel #6
0
        void Update()
        {
            if (useMouse)
            {
                fire = Input.GetMouseButton(0);
            }
            else
            {
                fire = Input.GetKey(KeyCode.Space);
            }

            if (useMouse)
            {
                curPos = new Vector2(Input.mousePosition.x / Screen.width * 2 - 1, Input.mousePosition.y / Screen.height * 2 - 1);
            }
            else
            {
                curPos = new Vector2(Mathf.Clamp(m_SliderX.value, -1, 1), Mathf.Clamp(m_SliderY.value, -1, 1));
                if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
                {
                    m_SliderX.value -= Time.deltaTime * 0.5f;
                }
                else if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
                {
                    m_SliderX.value += Time.deltaTime * 0.5f;
                }
            }
            curPos                  = new Vector2(Mathf.Clamp(curPos.x, -1, 1), Mathf.Clamp(curPos.y, -1, 1));
            m_SliderX.value         = curPos.x;
            m_SliderY.value         = curPos.y;
            GameParameter.ControlXY = (curPos + lastPosM) / (lastPos.Length + 1);

            CrossBow.gameObject.SetActive(true);
            CrossBow.transform.localEulerAngles     = new Vector3(-GameParameter.ControlXY.y * 12f, GameParameter.ControlXY.x * 45f, 0);
            CrossBow.transform.position             = CrossBowStartPos; // + new Vector3(0, 0, 3.3f) * GameParameter.ControlXY.x;
            CameraParent.transform.localEulerAngles = new Vector3(-GameParameter.ControlXY.y * 10f, GameParameter.ControlXY.x * 40f, 0);
            CameraParent.transform.position         = CrossBowStartPos; // + new Vector3(0, 0, 3f) * GameParameter.ControlXY.x;
            if (CrossBow.Fire)
            {
                Camera.main.fieldOfView = ValueAdjust.Lerp(Camera.main.fieldOfView, 20, Time.deltaTime, 10);
            }
            else
            {
                Camera.main.fieldOfView = ValueAdjust.Lerp(Camera.main.fieldOfView, 60, Time.deltaTime, 40);
            }

            GameParameter.Fire = fire;
            lastPosM           = Vector2.zero;
            for (int i = lastPos.Length - 1; i >= 0; i--)
            {
                if (i == 0)
                {
                    lastPos[0] = curPos;
                }
                else
                {
                    lastPos[i] = lastPos[i - 1];
                }
                lastPosM += lastPos[i];
            }
        }
Beispiel #7
0
 private void LateUpdate()
 {
     if (canPlayFireEffect)//发射
     {
         ColdDownTime = 0;
         ShotNum++;
         canPlayFireEffect = false;
         m_Audio.PlayOneShot(audioClips[Random.Range(1, audioClips.Length)]);//播放射出音效
         Arrow_Anim.GetComponent <Renderer>().enabled = false;
         Transform newArrow = Instantiate(Arrow_Prefab, Arrow_Anim.transform.position, this.transform.rotation);
         //newArrow.localScale = this.transform.localScale + Vector3.one * (Force - Force_Min) / (Force_Max - Force_Min);
         newArrow.GetComponent <Arrow>().m_Rigidbody.AddForce(this.transform.forward * Force);
         newArrow.name += ShotNum + "_" + Force.ToString("F2");
         Force          = Force_Min;
         BoresightTime  = 1f;
     }
     if (Holding)
     {
         if (!m_Audio.isPlaying)
         {
             m_Audio.PlayOneShot(audioClips[0]);//播放拉弦音效
         }
         Arrow_Anim.GetComponent <Renderer>().enabled = true;
     }
     if (canShowBoresight)
     {
         boresight.material.color = ColorAdjust.ColorAlphaChange(boresight.material.color, ValueAdjust.Lerp(boresight.material.color.a, 0.6f, Time.deltaTime, 5f));
     }
     else
     {
         boresight.material.color = ColorAdjust.ColorAlphaChange(boresight.material.color, ValueAdjust.Lerp(boresight.material.color.a, 0f, Time.deltaTime, 2f));
     }
 }