public void GolfSwing(GolfBall golfball) { if (!golfball || !IsPrepped) { return; } BallRetrieval br = golfball.GetComponent <BallRetrieval>(); float power = Mathf.Lerp(clubStats.MinDistance, clubStats.MaxDistance, powerOnRelease / clubStats.TimeForMaxDistance); if (br) { golfball.GetComponent <BallRetrieval>().SetNewBallPos(); } Vector3 dir = transform.root.forward; dir = Vector3.RotateTowards(dir, new Vector3(dir.x, dir.y + clubStats.VectorYIncrease, dir.z), 1, 0.0f); dir = dir.normalized * power; if (!NetworkManager.instance) { StartCoroutine(NoNetworkingWaitForSwing(golfball, dir)); } else { int id = golfball.IsAbilityBall() ? -1 : golfball.gameObject.transform.GetSiblingIndex(); int targetID = -1; Honing theHone = golfball.gameObject.GetComponent <Honing>(); if (clubStats.ClubName == "Driver" && theHone != null) { targetID = theHone.GetIDOfClosestPlayer(); } StartCoroutine(NetworkingWaitForSwing(golfball.gameObject, id, dir, golfball.IsAbilityBall(), clubStats.ClubName == "Driver", targetID)); } StartCoroutine(WaitForSwing(golfball, clubStats, power)); }
IEnumerator NoNetworkingWaitForSwing(GolfBall golfBall, Vector3 dir) { while (!swing) { yield return(new WaitForEndOfFrame()); } golfBall.GetComponent <Rigidbody>().velocity = dir; if (clubStats.ClubName == "Driver") { Honing theHone = golfBall.gameObject.GetComponent <Honing>(); GameObject obj = theHone?.GetObjOfClosestPlayer(); if (obj != null) { theHone.HoneToPlayer(obj); } } }
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; } }