protected virtual void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("GolfBall") && network && network.IsHost()) { GolfBall ball = collision.gameObject.GetComponent <GolfBall>(); if (ball.GetVelocity().sqrMagnitude >= golfBallSpeedThreshold * golfBallSpeedThreshold) { TakeDamage(ball.GetDamage(), ball.GetLastShotId()); } } }
private IEnumerator DelayedBallDespawn(GolfBall gb, float lifetime) { yield return(new WaitForSeconds(lifetime)); int team = nStoredData ? nStoredData.GetTeam(gb.GetLastShotId()) : 0; if (network && network.IsHost()) { EventController.FireEvent(new PersonalScoreMessage(gb.GetLastShotId(), PersonalScoreManager.TYPE.SCORE_BALL)); gb.EndLifetime(); EventController.FireEvent(new NetworkSendBallRespawn(gb, team)); } if (!network) { gb.EndLifetime(); EventController.FireEvent(new TeamScoreMessage()); } holeManager.ChangeHole(); dbsRoutine = null; }
private GameObject GetClosestPlayer(Collider[] players) { int index = -1; float distance = float.MaxValue; Vector3 direction; float squareMag = -1; for (int i = 0; i < players.Length; i++) { if (nStoredData) { EntityHealth target = players[i].GetComponent <EntityHealth>(); if (target != null) { int playerId = target.MyID; if (nStoredData.GetTeam(playerId) == nStoredData.GetTeam(myGolfBall.GetLastShotId())) { continue; } } } direction = players[i].gameObject.transform.position - transform.position; if (Vector3.Dot(rb.velocity.normalized, direction.normalized) > 0) //Is in screen view { squareMag = Vector3.SqrMagnitude(direction); if (squareMag < distance) { index = i; distance = squareMag; } } } if (index >= 0) { return(players[index].gameObject); } else { return(null); } }
public void CheckBallScore(GolfBall gb) { if (isActive) { //Ensure the ball is colored and not an ability ball if (gb is ColoredBall cb) { gb.gameObject.GetComponent <Rigidbody>().velocity = Vector3.zero; EventController.FireEvent(new TrackSuperlativeMessage(SuperlativeController.Superlative.Albatross, SuperlativeController.ConditionFlag.identity, Vector3.Distance(transform.position, gb.GetComponent <BallRetrieval>().GetLastPos()), gb.GetLastShotId())); if (!network || (network && network.IsHost())) { StartCoroutine(BeamFlash()); if (dbsRoutine == null) { dbsRoutine = StartCoroutine(DelayedBallDespawn(gb, duration)); SoundManager.PlaySoundAt("Ball Scored", transform.position); SoundManager.PlaySound("Golf Clap"); } } //For tutorial purposes if (PlayerTutorialChecker.instance != null) { PlayerTutorialChecker.instance.BallScored(); } return; } else if (gb is AbilityBall ab) { ab.GetComponent <Rigidbody>().velocity *= yeetFactor; } } else { gb.GetComponent <Rigidbody>().velocity *= yeetFactor; } }