Ejemplo n.º 1
0
 void Update()
 {
     if (IsPlaying || isPlaying)
     {
         if (IsDown)
         {
             mp     = MP;
             staPos = transform.position;
         }
         if (IsClick)
         {
             pos = staPos + new Vector3(MP.x - mp.x, 0, MP.y - mp.y) * posScl;
         }
         dis = V3.Dis(transform.position, pos);
         if (dis < 0.1f)
         {
             transform.position = pos;
             rb.V0();
         }
         else
         {
             transform.LookAt(pos);
             rb.velocity = transform.forward * M.Clamp01(dis / disTh) * speed;
         }
     }
     else
     {
         rb.V0();
     }
 }
 void Update()
 {
     if (IsPlaying || isPlaying)
     {
         if (IsDown)
         {
             mp = MP;
         }
         if (IsClick)
         {
             dis = V3.Dis(MP, mp);
             if (dis > radius)
             {
                 mp = V3.Move(MP, mp, radius);
             }
             horseTf.rotation = Q.Euler(0, Ang.LookForward(mp, MP), 0);
         }
         if (IsUp)
         {
             rb.V0();
         }
     }
     else
     {
         rb.V0();
     }
 }
Ejemplo n.º 3
0
    ///<summary>pnts-н цэгүүдийн зай</summary>
    public static float PntsDis(List <Vector3> pnts)
    {
        float res = 0;

        for (int i = 1; i < pnts.Count; i++)
        {
            res += V3.Dis(pnts[i - 1], pnts[i]);
        }
        return(res);
    }
Ejemplo n.º 4
0
    void OnSceneGUI()
    {
        // input
        Event   e   = Event.current;
        Vector2 pos = model.TfInvPnt(HandleUtility.GUIPointToWorldRay(e.mousePosition).origin);

        // select index segment
        int selIdx = -1, selSeg = -1;

        for (int i = 0; i < model.points.Count; i++)
        {
            if (V3.Dis(model.points[i], pos) < 0.1f)
            {
                selIdx = i;
            }
            if (i == 0 && HandleUtility.DistancePointLine(pos, model.points[i], V2.X(model.points[i], 0)) < 0.1f)
            {
                selSeg = 0;
            }
            if (i >= 1 && HandleUtility.DistancePointLine(pos, model.points[i - 1], model.points[i]) < 0.1f)
            {
                selSeg = i;
            }
        }

        // add point
        if (e.type == EventType.MouseDown && e.button == 0 && e.shift)
        {
            model.points.Insert(selSeg >= 0 ? selSeg : model.points.Count, pos);
        }

        // delete point
        if (e.type == EventType.MouseDown && e.button == 1 && selIdx >= 0)
        {
            model.points.RemoveAt(selIdx);
        }

        // draw
        Handles.color = Col.red;
        for (int i = 0; i < model.points.Count; i++)
        {
            model.points[i] = model.TfInvPnt(
                Handles.FreeMoveHandle(
                    model.TfInvPnt(model.points[i]),
                    Q.O, 0.1f, V3.O, Handles.CylinderHandleCap
                    )
                );
        }
        model.UpdateMesh();
    }
Ejemplo n.º 5
0
    ///<summary>a-с b-рүү ang өнцөгтэй явах үеийн анхны хурд, хугацаа, өндөр</summary>
    public static Vector3 Ang(Vector3 a, Vector3 b, float ang, ref float time, ref float h)
    {
        float   g = Physics.gravity.y;
        Vector3 aXz = V3.Y(a, 0), bXz = V3.Y(b, 0);
        float   disXz    = V3.Dis(aXz, bXz);
        float   tanAlpha = Mathf.Tan(ang * Mathf.Deg2Rad);
        float   disY     = b.y - a.y;
        float   vZ       = Mathf.Sqrt(g * disXz * disXz / (2f * (disY - disXz * tanAlpha)));
        float   vY       = tanAlpha * vZ;
        Vector3 v0       = Q.LookRot(bXz - a) * new Vector3(0f, vY, vZ);

        h    = -v0.y * v0.y / (2 * g);
        time = time = Mathf.Sqrt(-2 * h / g) + Mathf.Sqrt(2 * (disY - h) / g);
        return(v0);
    }
Ejemplo n.º 6
0
    void Update()
    {
        if (IsPlaying)
        {
            if (IsDown)
            {
                MouseButtonDown();
            }

            if (IsClick)
            {
                Controller();
            }

            if (IsUp)
            {
                animator.SetBool("Run", false);
                isLasso = true;
            }

            if (isLasso)
            {
                lasso.transform.position += transform.forward * Time.deltaTime * 20f;
                Vector3 vPort = A.Cam.WorldToScreenPoint(lasso.transform.position);
                if (vPort.y < 0 || vPort.y > A.Cam.pixelHeight || vPort.x < 0 || vPort.x > A.Cam.pixelWidth)
                {
                    isLassoOutScreen = true;
                }

                if (isLassoOutScreen)
                {
                    if (V3.Dis(lasso.transform.position, lassoStartTf.position) > 0.5f)
                    {
                        lasso.transform.position = V3.Move(lasso.transform.position, lassoStartTf.position, 0.5f);
                    }
                    else
                    {
                        isLasso          = false;
                        isLassoOutScreen = false;
                    }
                }
            }
        }
    }