示例#1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Ground") && (spearState == SpearState.Thrown || spearState == SpearState.Returning))
        {
            rb.constraints = RigidbodyConstraints2D.FreezeAll;
            rb.velocity    = Vector2.zero;
            spearState     = SpearState.Landed;
            box.enabled    = true;

            impactSystem.Play();
        }
        if (other.CompareTag("Enemy") && (spearState == SpearState.Thrown || spearState == SpearState.Returning))
        {
            //TODO: enemies take damage
            other.GetComponent <EnemyHealth>().TakeDamage(spearDamage);
            other.attachedRigidbody.AddForce(rb.velocity * 10f);
        }

        /*if (other.CompareTag("Player") && spearState == SpearState.Returning)
         * {
         *  character.EquipSpear(this);
         *  Vector3 dir = character.transform.position - transform.position;
         *  character._rigidbody.AddForce(dir * recoil);
         * }*/
    }
示例#2
0
    private void OnTriggerStay2D(Collider2D other)
    {
        // so it doesnt get stuck if thrown while inside a wall
        if (other.CompareTag("Ground") && (spearState == SpearState.Thrown || spearState == SpearState.Returning))
        {
            rb.constraints = RigidbodyConstraints2D.FreezeAll;
            rb.velocity    = Vector2.zero;
            spearState     = SpearState.Landed;
            if (Physics2D.OverlapCircle(transform.position, 0.5f, LayerMask.GetMask("Player")))
            {
                box.enabled = false;
            }
            else
            {
                box.enabled = true;
            }
            impactSystem.Play();
        }
        if (other.CompareTag("Enemy") && (spearState == SpearState.Thrown || spearState == SpearState.Returning))
        {
            //TODO: enemies take damage
            other.GetComponent <EnemyHealth>().TakeDamage(spearDamage);
            other.attachedRigidbody.AddForce(rb.velocity * 10f);
        }

        /*if (other.CompareTag("Player") && spearState == SpearState.Returning)
         * {
         *  character.EquipSpear(this);
         *  Vector3 dir = character.transform.position - transform.position;
         *  character._rigidbody.AddForce(dir * recoil);
         *
         * }*/
    }
示例#3
0
    private void Update()
    {
        if (this == character._spear)
        {
            if (Input.GetKey(KeyCode.Mouse1) && (spearState == SpearState.Thrown || spearState == SpearState.Returning))
            {
                Vector3 dir = character.transform.position - transform.position;
                rb.velocity = rb.velocity.magnitude * dir.normalized;
                float AngleRad = Mathf.Atan2(dir.y - transform.position.y, dir.x - transform.position.x);
                float angle    = (180 / Mathf.PI) * AngleRad;

                /*
                 * transform.eulerAngles = new Vector3(0f, 0f, angle);
                 */
                spearState = SpearState.Returning;

                transform.right = dir;
            }
            if (Input.GetKey(KeyCode.Mouse1) && spearState == SpearState.Landed)
            {
                rb.constraints = RigidbodyConstraints2D.None;
                box.enabled    = false;
                Vector3 dir      = character.transform.position - transform.position;
                float   AngleRad = Mathf.Atan2(dir.y - transform.position.y, dir.x - transform.position.x);
                float   angle    = (180 / Mathf.PI) * AngleRad;

                /*
                 * transform.eulerAngles = new Vector3(0f, 0f, angle);
                 */


                transform.right = dir;

                rb.velocity          = dir.normalized * character.throw_force / speedDivider;
                spearState           = SpearState.Returning;
                character.attackMode = PlayerMovement.AttackMode.Melee;
            }
        }
    }