예제 #1
0
 private void Move(float param)
 {
     if (GameDefine.FloatIsZero(param))
     {
         Rigidbody.velocity = new Vector2(0, 0);
     }
     else
     {
         Rigidbody.velocity = new Vector2(Rigidbody.velocity.x, param * GameDefine.PlayerMaxSpeed);
     }
 }
예제 #2
0
        private Vector3 CalcLinePos(Vector3 A, Vector3 B, float len)
        {
            var lenAB = Mathf.Sqrt((B.y - A.y) * ((B.y - A.y)) + (B.x - A.x) * (B.x - A.x));// 计算2点的长度

            float dy = B.y - A.y;
            float dx = B.x - A.x;

            float sinT = 0f, cosT = 0f;
            float x = 0f, y = 0f;

            if (!GameDefine.FloatIsZero(dy) && !GameDefine.FloatIsZero(dx))
            {
                sinT = dy / lenAB;
                cosT = dx / lenAB;
                y    = B.y + len * sinT;
                x    = B.x + len * cosT;
            }
            else if (GameDefine.FloatIsZero(dy) && dx > 0.0f)
            {
                y = B.y;
                x = B.x + len;
            }
            else if (dy > 0.0f && GameDefine.FloatIsZero(dx))
            {
                y = B.y + len;
                x = B.x;
            }
            else if (GameDefine.FloatIsZero(dy) && dx < 0.0f)
            {
                y = B.y;
                x = B.x - len;
            }
            else if (dy < 0.0f && GameDefine.FloatIsZero(dx))
            {
                y = B.y - len;
                x = B.x;
            }

            return(new Vector3(x, y, 0));
        }