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"); } } }
/// <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"); } }