コード例 #1
0
    private void Knockback(GameObject knockbackObj)
    {
        // tried to find a movement controller, if null return out of statement
        MovementController Mc = knockbackObj.GetComponentInChildren <MovementController>();

        if (Mc == null)
        {
            return;
        }

        // get direction between the two objects
        Vector3 knockback = Vector2.zero;

        if (useRotation)
        {
            knockback += transform.rotation * Vector3.right;
        }
        else
        {
            knockback += (knockbackObj.transform.position - transform.position).normalized;
        }

        // multiplies direction by the force of the knockback
        knockback *= knockbackForce;

        // applies the knockback to the movement controller
        Mc.AddKnockback(knockback);
    }
コード例 #2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        var sword = other.GetComponent <SwordsHit>();;

        if (sword != null && this != sword)
        {
            mc.AddKnockback((mc.transform.position - sword.mc.transform.position).normalized * force);
            GameObject go = Instantiate(hitParticlePrefab);
            go.transform.position = (mc.transform.position + sword.mc.transform.position) / 2f;

            /*
             * parallel lines dont intersect?;
             * Vector2 intersectionPoint;
             * var s1 = (Vector2)mc.transform.position;
             * var s2 = (Vector2)sword.mc.transform.position;
             * var e1 = s1 + (mc.Ic.lookDirection * 2f);// force is not the righgt variable here.. is should be the tip off the swordGameobject.
             * var e2 = s2 + (sword.mc.Ic.lookDirection * 2f);// force is not the righgt variable here.. is should be the tip off the swordGameobject.
             * Debug.Log(LineSegmentsIntersection(s1, e1, s2, e2, out intersectionPoint));
             *
             * go.transform.position = new Vector3(intersectionPoint.x, intersectionPoint.y, go.transform.position.z);
             * Debug.Log(go.transform.position);
             */
        }
    }