Exemplo n.º 1
0
 public void setCurrentAngle(float n_angle360)
 {
     if (angle_base != n_angle360)
     {
         angle_base = n_angle360;
         //auto define direction
         directionTended = angleToDirection(angle_base);
     }
 }
Exemplo n.º 2
0
    TendDirection angleToDirection(float in_angle360)
    {
        float         angle_form = in_angle360 % 360;
        TendDirection out_dir    = TendDirection.undefine;

        if (angle_form > 360 - 1 && angle_form < 1)     //is up
        {
            out_dir = TendDirection.up;
        }
        if (angle_form > 90 - 1 && angle_form < 90 + 1)   //is left
        {
            out_dir = TendDirection.left;
        }
        if (angle_form > 90 - 1 && angle_form < 90 + 1)   //is right
        {
            out_dir = TendDirection.right;
        }
        if (angle_form > 270 - 1 && angle_form < 270 + 1)   //is left
        {
            out_dir = TendDirection.left;
        }

        if (angle_form >= 1 && angle_form <= 90 - 1)
        {
            out_dir = TendDirection.upright;
        }

        if (angle_form >= 270 + 1 && angle_form <= 360 - 1)
        {
            out_dir = TendDirection.upleft;
        }

        if (angle_form >= 180 + 1 && angle_form <= 270 - 1)
        {
            out_dir = TendDirection.downleft;
        }

        if (angle_form >= 90 + 1 && angle_form <= 180 - 1)
        {
            out_dir = TendDirection.downright;
        }

        return(out_dir);
    }
Exemplo n.º 3
0
    public void SetOopAdj(Vector3 oA, Vector3 oB)
    {
        //reset
        angle_base = 0F;
        angleInTan = 0F;

        if (!oA.Equals(oB))
        {
            float opp = Mathf.Max(oA.z, oB.z) - Mathf.Min(oA.z, oB.z);
            float adj = Mathf.Max(oA.x, oB.x) - Mathf.Min(oA.x, oB.x);

            distance = Mathf.Sqrt(Mathf.Pow(opp, 2F) + Mathf.Pow(adj, 2F));

            if (opp > 0.1 && adj > 0.1)
            {
                angleInTan = (Mathf.Atan(opp / adj) * Mathf.Rad2Deg);
            }
            if (oA.z != oB.z || oA.x != oB.x)
            {
                if (opp < 0.1 || adj < 0.1)
                {
                    if (adj < 0.1)
                    {
                        if (oA.z < oB.z)
                        {
                            angle_base      = 0F;
                            angle_refact    = 180F;
                            directionTended = TendDirection.up;
                            directionRefact = TendDirection.down;
                        }
                        else if (oA.z > oB.z)
                        {
                            angle_base      = 180F;
                            angle_refact    = 0F;
                            directionTended = TendDirection.down;
                            directionRefact = TendDirection.up;
                        }
                    }
                    else if (opp < 0.1)
                    {
                        if (oA.x < oB.x)
                        {
                            angle_base      = 90F;
                            angle_refact    = 270F;
                            directionTended = TendDirection.right;
                            directionRefact = TendDirection.left;
                        }
                        else if (oA.x > oB.x)
                        {
                            angle_base      = 270F;
                            angle_refact    = 90F;
                            directionTended = TendDirection.left;
                            directionRefact = TendDirection.right;
                        }
                    }
                }
                else if (oA.x < oB.x)                  //target on right
                {
                    float _base   = 90F;
                    float _refact = 270F;
                    if (oA.z < oB.z)                     //target on top
                    {
                        angle_base      = _base - angleInTan;
                        angle_refact    = _refact - angleInTan;
                        directionTended = TendDirection.upright;
                        directionRefact = TendDirection.downleft;
                    }
                    else if (oA.z > oB.z)                      //target on down
                    {
                        angle_base      = _base + angleInTan;
                        angle_refact    = _refact + angleInTan;
                        directionTended = TendDirection.downright;
                        directionRefact = TendDirection.upleft;
                    }
                }
                else if (oA.x > oB.x)                  // target on left
                {
                    float _base   = 270F;
                    float _refact = 90F;
                    if (oA.z < oB.z)                     //target on top
                    {
                        angle_base      = _base + angleInTan;
                        angle_refact    = _refact + angleInTan;
                        directionTended = TendDirection.upleft;
                        directionRefact = TendDirection.downright;
                    }
                    else if (oA.z > oB.z)                      //target on down
                    {
                        angle_base      = _base - angleInTan;
                        angle_refact    = _refact - angleInTan;
                        directionTended = TendDirection.downleft;
                        directionRefact = TendDirection.upright;
                    }
                }
            }
            //				Debug.Log("A("+oA.x+","+oA.z+")  B("+oB.x+","+oB.z+")");
//							Debug.Log(" target in "+ directionTended+" , refact"+ directionRefact );
        }
    }
Exemplo n.º 4
0
 public void setCurrentDirect(TendDirection n_direct)
 {
     directionTended = n_direct;
 }