Example #1
0
    /// <summary>
    /// 既にリンクされた線と線の接触判定
    /// </summary>
    void CheckFuck()
    {
        WireStates prev     = null;
        WireStates prevPrev = null;

        List <WireStates> addList = new List <WireStates>();
        List <WireStates> delList = new List <WireStates>();

        int num = 0;

        foreach (WireStates current in WIres)
        {
            if (prev != null)
            {
                if (Vector3.Distance(prev.transform.position, current.transform.position) > minRange)
                {
                    if (Physics.Linecast(prev.transform.position, current.transform.position, out RaycastHit hit, mask))
                    {
                        DrawHitTriangles(hit);

                        Add(hit.transform, hit.rigidbody, hit.normal, num, hit.point, addList, true, current.transform);
                        num++;
                    }
                }

                if (prevPrev != null)
                {
                    Vector3 thisPos = prevPrev.transform.position;
                    Vector3 nextPos = prev.transform.position;

                    Vector3 dotPos = thisPos - nextPos;

                    //float dot = Vector3.Dot((current.transform.forward+prev.transform.forward).normalized, dotPos);
                    //if (dot > ofsRange)
                    //{
                    if (!Physics.Linecast(thisPos, current.transform.position, out RaycastHit hit, mask))
                    {
                        delList.Add(prev);
                    }
                    //}
                }
            }

            prevPrev = prev;
            prev     = current;
            num++;
        }

        //生成した点を本体のリストに追加
        foreach (WireStates ws in addList)
        {
            WIres.Insert(ws.num, ws);
        }

        //消えるべき点を本体から消す
        foreach (WireStates ws in delList)
        {
            WIres.Remove(ws);
        }
    }
Example #2
0
    // Update is called once per frame
    /// <summary>
    /// 線の表示,線と線を引き合わせる
    /// </summary>
    void Update()
    {
        Vector3 prePos = transform.position;

        WireStates prev    = null;
        float      stretch = Mathf.Max(1f, currentWireRange - wireRange);

        foreach (var current in WIres)
        {
            Spring(prev, current, stretch);
            prev = current;



            //描画
            Debug.DrawLine(current.transform.position, prePos);
            Debug.DrawLine(current.transform.position, current.transform.position + current.transform.forward);
            prePos = current.transform.position;
        }
    }
Example #3
0
    void Spring(WireStates prev, WireStates current, float stretch)
    {
        if (current == null || prev == null)
        {
            return;
        }

        if (current.rigidbody && prev.rigidbody)
        {
            if (prev.rigidbody == current.rigidbody)
            {
                return;
            }
        }

        Vector3 vel = Vector3.ClampMagnitude((prev.transform.position - current.transform.position), springClamp);

        current.rigidbody?.AddForceAtPosition(vel * springPow * stretch, current.transform.position);
        prev.rigidbody?.AddForceAtPosition(vel * -springPow * stretch, prev.transform.position);


        ////20200601追加 フックオブジェクトのターゲットリジッドボディに親がいれば、その親にもアドフォース
        //if (current.rigidbody && current.rigidbody.transform.parent)
        //{
        //    Rigidbody parentRB = current.rigidbody.transform.parent.GetComponent<Rigidbody>();
        //    if (parentRB)
        //    {
        //        parentRB.AddForceAtPosition(vel * springPow * stretch *0.5f, current.transform.position);
        //    }
        //}
        //if (prev.rigidbody && prev.rigidbody.transform.parent)
        //{
        //    Rigidbody parentRB = prev.rigidbody.transform.parent.GetComponent<Rigidbody>();
        //    if (parentRB)
        //    {
        //        parentRB.AddForceAtPosition(vel * -springPow * stretch*0.5f, prev.transform.position);
        //    }
        //}
    }
Example #4
0
 /// <summary>
 //リンク点とそれに伴って生成したゲームオブジェクトの破棄
 /// </summary>
 /// <param name="ws">破棄するリストオブジェクト</param>
 void Remove(WireStates ws)
 {
     Destroy(ws.transform.gameObject);
     WIres.Remove(ws);
 }