Esempio n. 1
0
 /// <summary>
 /// 添加球推动方向
 /// </summary>
 /// <param name="t"></param>
 private void AddBallPush(BallPushType t)
 {
     if ((pushType & t) != t)
     {
         pushType |= t;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 去除球推动方向
 /// </summary>
 /// <param name="t"></param>
 private void RemoveBallPush(BallPushType t)
 {
     if ((pushType & t) == t)
     {
         pushType ^= t;
     }
 }
Esempio 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);
                    }
                }
            }
        }