Example #1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("NPC") || other.CompareTag("Player") || other.CompareTag("Ragdoll"))
        {
            float angle = Vector2Extension.DirectionAngle(other.transform.position - transform.position);

            if (angle > 180 && angle < 270)
            {
                float amountOver = angle - 180;
                angle -= 2 * amountOver;
            }
            else if (angle >= 270)
            {
                float amountUnder360 = 360 - angle;
                angle = amountUnder360;
            }

            if (other.CompareTag("Ragdoll"))
            {
                DixieRagdoll ragdoll = other.GetComponent <DixieRagdoll>();
                if (ragdoll != null)
                {
                    ragdoll.SetForceDirection(power, angle);
                }
            }
            else
            {
                HealthSystem healthSystem = other.GetComponent <HealthSystem>();


                healthSystem.TakeDamage(25, angle);
            }
        }
    }
    public FloorNode InstantiateFloorNode(Vector2 u, Vector2 v)
    {
        // get direction/angle
        // get midpoint along vector
        // instantiate nice WalkNodes with dimensions that will stick out the proper amount (height should be 3)

        Vector3 midpoint = new Vector3((u.x + v.x) / 2 + transform.position.x, (u.y + v.y) / 2 + transform.position.y, 0);
        //I'm not sure if this is correct. Assume u is the tail
        float angle = Vector2Extension.DirectionAngle(v - u);

        float width = Vector2.Distance(u, v);

        GameObject floorNodePrefab = Resources.Load("Prefabs/FloorNodePrefab") as GameObject;

        GameObject walkNodeGameObject = Instantiate <GameObject>(floorNodePrefab);

        walkNodeGameObject.transform.SetPositionAndRotation(midpoint, Quaternion.Euler(0, 0, angle));
        walkNodeGameObject.transform.localScale = new Vector3(width, 2, 1);
        return(walkNodeGameObject.AddComponent <FloorNode>());
    }