Пример #1
0
 private void checkBallHitPlayer()
 {
     hitsPlayer = Physics.OverlapCapsule(transform.position + hitPoint0, transform.position + hitPoint1, hitRadius, collisionMask);
     if (hitsPlayer.Length > 0 && healCooldownTimer <= 0)
     {
         healCooldownTimer = healCooldown;
         for (int i = 0; i < hitsPlayer.Length; ++i)
         {
             sphereController sphere = hitsPlayer[i].GetComponent <sphereController>();
             if (team.currentTeam != sphere.GetTeam.currentTeam)
             {
                 Debug.Log("Enemy Ball " + hitsPlayer[i].gameObject.name + " has destroyed " + gameObject.name);
                 playerDeath();
             }
             else
             {
                 Debug.Log("Friendly Ball " + hitsPlayer[i].gameObject.name + " has hit " + gameObject.name + ". Healing by 1");
                 if (HP < maxHP)
                 {
                     HP        += 1;
                     tmpHP.text = "HP: " + HP.ToString();
                 }
             }
         }
     }
 }
Пример #2
0
    public void ballHitInputPassthrough()
    {
        hit = Physics.BoxCast(col.bounds.center, col.size, transform.forward, out raycastHit, transform.parent.rotation, maxDistance);
        if (hit && cooldownTimer <= 0)
        {
            cooldownTimer = cooldown;
            Debug.Log("Player " + transform.name + " Hit object " + raycastHit.collider.name);
            Rigidbody        sphereRB = raycastHit.transform.GetComponent <Rigidbody>();
            sphereController sphere   = raycastHit.transform.GetComponent <sphereController>();

            // Calculate hit
            sphereRB.velocity        = Vector3.zero;
            sphereRB.angularVelocity = Vector3.zero;
            float yHitDir = 0;
            if (transform.forward.y >= 0)
            {
                yHitDir = (transform.forward.y + 3) * ballHitStrengthUp;
            }
            else
            {
                yHitDir = (transform.forward.y * 2) * ballHitStrengthUp;
            }

            // Add force to ball to hit it away
            sphereRB.AddForce(new Vector3(transform.forward.x * ballHitStrengthForward, yHitDir, transform.forward.z * ballHitStrengthForward));

            // determine if friendly or enemy
            if (pgc.getTeam.currentTeam == sphere.GetTeam.currentTeam)
            {
                // If friendly, heal
                if (pgc.HP < pgc.maxHP)
                {
                    pgc.HP        += 1;
                    pgc.tmpHP.text = "HP: " + pgc.HP.ToString();
                    Debug.Log("Punched friendly ball, healing by 1");
                }
            }
            else
            {
                // if enemy, take 1 hit and turn ball friendly
                pgc.HP        -= 1;
                pgc.tmpHP.text = "HP: " + pgc.HP.ToString();
                if (sphere.GetTeam.currentTeam == TeamObject.Team.BLU)
                {
                    sphere.setTeam("red");
                }
                else
                {
                    sphere.setTeam("blu");
                }
                Debug.Log("Punched enemy ball, hit by 1, switched ball to friendly side");
            }
        }
    }
Пример #3
0
    /// <Summary>
    /// Spawn's ball at a random point of the spawn locations. When it spawns, the ball is given a team
    /// based on which side the ball spawns on. Even = Blu, Odd = Red
    /// </Summary>
    private void createBallRandomLoc()
    {
        int              spawnPos = (int)Random.Range(0, spawnLocs.Count);
        GameObject       clone    = Instantiate(ballsToSpawn, transform.position + spawnLocs[spawnPos], Quaternion.identity);
        sphereController sphere   = clone.GetComponent <sphereController>();

        if (spawnPos % 2 == 0)
        {
            sphere.setTeam("blu");
        }
        else
        {
            sphere.setTeam("red");
        }
    }
Пример #4
0
    private void checkBallIncoming()
    {
        hits = Physics.OverlapSphere(transform.position, ballCheckRadius, collisionMask);

        if (hits.Length > 0)
        {
            for (int i = 0; i < hits.Length; ++i)
            {
                // sphereController sphere = ballHitCheck.transform.GetComponent<sphereController>();
                sphereController sphere = hits[i].GetComponent <sphereController>();

                // Ball is on same team, set color to friendly
                if (team.currentTeam == sphere.GetTeam.currentTeam)
                {
                    sphere.setColorFriendly();
                }
                else
                {
                    sphere.setColorEnemy();
                }
            }
        }
    }