Ejemplo n.º 1
0
 //摄像机跟随 每帧
 private void CamFollow()
 {
     if (camFollowTarget == null)
     {
         isFollowCam = false;
         return;
     }
     if (isFollowCam)
     {
         if (!CurrentBall.IsNull())
         {
             GameBall ball = ((GameBall)CurrentBall.Data());
             ballCamFollowTarget.transform.position = Vector3.SmoothDamp(ballCamFollowTarget.transform.position, ball.transform.position, ref camVelocityTarget2, camFollowSpeed2);
             ballCamFollowTarget.transform.position = new Vector3(ballCamFollowTarget.transform.position.x, ball.transform.position.y, ballCamFollowTarget.transform.position.z);
             ballCamFollowHost.transform.position   = Vector3.SmoothDamp(ballCamFollowHost.transform.position, ball.transform.position, ref camVelocityTarget, camFollowSpeed);
         }
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 平滑移动球到指定位置。
        /// </summary>
        /// <param name="pos">指定位置。</param>
        /// <param name="off">动画平滑时间</param>
        private void SmoothMoveBallToPos(Vector3 pos, float off = 2f)
        {
            if (CurrentBall != null)
            {
                if (IsControlling.BoolData())
                {
                    IsControlling.SetData(currentContext, false);
                }
                RemoveBallSpeed(CurrentBall.Data <GameBall>());
                ballSmoothMoveTarget = pos;
                ballSmoothMoveTime   = off;

                isBallSmoothMove = true;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 推动
        /// </summary>
        public virtual void BallPush()
        {
            if (IsControlling.BoolData())
            {
                FinalPushForceVectorFB = Vector3.zero;
                FinalPushForceVectorLR = Vector3.zero;
                pushPositionLocal.x    = transform.position.x + PushForcePosition.x;
                pushPositionLocal.y    = transform.position.y + PushForcePosition.y;
                pushPositionLocal.z    = transform.position.z + PushForcePosition.z;

                //获取 ballsManager 的球推动类型。
                BallPushType currentBallPushType = PushType.Data <BallPushType>();
                if (currentBallPushType != BallPushType.None)
                {
                    if ((currentBallPushType & BallPushType.Forward) == BallPushType.Forward)
                    {
                        if (PushForceDownAngle > 0)
                        {
                            FinalPushForceVectorFB = Quaternion.AngleAxis(-PushForceDownAngle, thisVector3Left.Vector3Data()) *
                                                     thisVector3Forward.Vector3Data() * PushForce;
                        }
                        else
                        {
                            FinalPushForceVectorFB = thisVector3Forward.Vector3Data() * PushForce;
                        }
                    }
                    else if ((currentBallPushType & BallPushType.Back) == BallPushType.Back)
                    {
                        if (PushForceDownAngle > 0)
                        {
                            FinalPushForceVectorFB = Quaternion.AngleAxis(PushForceDownAngle, thisVector3Left.Vector3Data()) *
                                                     thisVector3Back.Vector3Data() * PushForce;
                        }
                        else
                        {
                            FinalPushForceVectorFB = thisVector3Back.Vector3Data() * PushForce;
                        }
                    }
                    if ((currentBallPushType & BallPushType.Left) == BallPushType.Left)
                    {
                        if (PushForceDownAngle > 0)
                        {
                            FinalPushForceVectorLR = Quaternion.AngleAxis(PushForceDownAngle, thisVector3Forward.Vector3Data()) *
                                                     thisVector3Left.Vector3Data() * PushForce;
                        }
                        else
                        {
                            FinalPushForceVectorLR = thisVector3Left.Vector3Data() * PushForce;
                        }
                    }
                    else if ((currentBallPushType & BallPushType.Right) == BallPushType.Right)
                    {
                        if (PushForceDownAngle > 0)
                        {
                            FinalPushForceVectorLR = Quaternion.AngleAxis(-PushForceDownAngle, thisVector3Forward.Vector3Data()) *
                                                     thisVector3Right.Vector3Data() * PushForce;
                        }
                        else
                        {
                            FinalPushForceVectorLR = thisVector3Right.Vector3Data() * PushForce;
                        }
                    }

                    if (FinalPushForceVectorFB != Vector3.zero)
                    {
                        Rigidbody.AddForceAtPosition(FinalPushForceVectorFB, pushPositionLocal, ForceMode);
                    }
                    if (FinalPushForceVectorLR != Vector3.zero)
                    {
                        Rigidbody.AddForceAtPosition(FinalPushForceVectorLR, pushPositionLocal, ForceMode);
                    }

                    //调试模式可以上下飞行
                    if (IsBallDebug.BoolData())
                    {
                        if ((currentBallPushType & BallPushType.Up) == BallPushType.Up) //上
                        {
                            Rigidbody.AddForce(Vector3.up * PushUpForce, ForceMode);
                        }
                        else if ((currentBallPushType & BallPushType.Down) == BallPushType.Down)    //下
                        {
                            Rigidbody.AddForce(Vector3.down * PushForce * 0.5f, ForceMode);
                        }
                    }
                }

                if (FallForce > 0 && (currentBallPushType & BallPushType.Up) != BallPushType.Up)
                {
                    Rigidbody.AddForce(Vector3.down * FallForce, ForceMode);
                }

                //Y轴移动最大速度(这个用来模拟下落空气阻力)
                if (MaxSpeedY > 0)
                {
                    float speedOut = Mathf.Abs(Rigidbody.velocity.y) - Mathf.Abs(MaxSpeedY);
                    if (speedOut > 0)
                    {
                        float force = (speedOut / MaxSpeedYCurrctRatio) * MaxSpeedYForceMax;
                        Rigidbody.AddForce((Rigidbody.velocity.y < 0 ? (Vector3.up) : Vector3.down) *
                                           (force + (Rigidbody.velocity.y < 0 ? FallForce : 0)),
                                           ForceMode);
                    }
                }

                //XZ轴移动最大速度(这个用来模拟移动空气阻力)
                if (MaxSpeedXZ > 0)
                {
                    float speedOutXZ = Mathf.Sqrt(Mathf.Pow(Rigidbody.velocity.x, 2) +
                                                  Mathf.Pow(Rigidbody.velocity.z, 2)) - Mathf.Abs(MaxSpeedXZ);
                    if (speedOutXZ > 0)
                    {
                        float force = (speedOutXZ / MaxSpeedXZCurrctRatio) * MaxSpeedXZForceMax;
                        pushVectorReverse.x = -Rigidbody.velocity.x;
                        pushVectorReverse.z = -Rigidbody.velocity.z;
                        Rigidbody.AddForce(pushVectorReverse * force, ForceMode);
                    }
                }
            }
        }