Example #1
0
    public bool CollisionCheck(GameObject otherObject, Vector2 newBodyVelocity)
    {
        // Setup
        SpaceObject otherSpaceObject = otherObject.GetComponent <SpaceObject>();
        Asteroid    otherAsteroid    = otherSpaceObject as Asteroid;

        float   otherDamage;
        Vector2 otherVelocity = otherSpaceObject.GetBodyVelocity();

        otherDamage = otherSpaceObject.GetScale();

        if ((int)GetScale() >= otherDamage && otherDamage > 0)
        {
            // Sound
            float volume = (scale < 10) ? scale / 10 : 1f;
            AudioManager.AM.Play(collisionSounds[Random.Range(0, collisionSounds.Length)], volume);

            // Push + Damage other object
            if (!knockbackImpaired)
            {
                otherSpaceObject.IncreaseBodyVelocity((newBodyVelocity) * GetScale() / 5);
            }

            otherSpaceObject.DealDamage((int)GetScale());

            // Push + Damage ourselves
            if (otherDamage > 0 && !otherSpaceObject.knockbackImpaired)
            {
                IncreaseBodyVelocity(otherVelocity * otherDamage / 5);
            }

            DealDamage((int)otherDamage);
            return(true);
        }

        return(false);
    }