Esempio n. 1
0
    void OnCollisionEnter(Collision collision)
    {
        // get the direction from player to collider
        Vector3 collisionNormal = (collision.transform.position - transform.position).normalized;

        // get player speed towards the collision
        float playerCollisionSpeed = Vector3.Dot(collisionNormal, rbody.velocity);
        float otherCollisionSpeed  = Vector3.Dot(-collisionNormal, collision.relativeVelocity + rbody.velocity);
        float collisionSpeed       = playerCollisionSpeed + otherCollisionSpeed;

        //Debug.Log("Collide!!!" + playerCollisionSpeed.ToString("F2") + ":::::" + otherCollisionSpeed.ToString("F2"));
        //Debug.Log("Overall speed" + collisionSpeed.ToString("F2"));
        if (collisionSpeed > 1)
        {
            anim.SetTrigger("TakeDamage");
            AudioManager.Instance.PlaySound(transform, damageSound);
            droneHealth -= (int)(collisionSpeed * 5);
            GUICanvas.SetHealth(droneHealth);
        }
    }