diff --git a/BackupCam.cs b/BackupCam.cs index 4cc199d..b215d5b 100644 --- a/BackupCam.cs +++ b/BackupCam.cs @@ -16,7 +16,8 @@ public class BackupCam : SonsMod { const float ReverseSpeed = -0.4f; const float HideDelay = 0.6f; - const float SearchInterval = 1f; + const float SearchInterval = 0.5f; + const float SearchRadius = 2.5f; const string ScreenPath = "GolfCartScreen/GolfCartGps/Canvas/ScreenMask"; const string ScreenImageName = "BackupCamScreen"; @@ -51,7 +52,7 @@ public class BackupCam : SonsMod protected override void OnSdkInitialized() { - RLog.Msg("BackupCam 1.1.0 loaded. Reverse the golf cart to show the camera on its GPS screen. Console: backupcamoffset, backupcamdump"); + RLog.Msg("BackupCam 1.1.1 loaded. Reverse the golf cart to show the camera on its GPS screen. Console: backupcamoffset, backupcamdump"); } protected override void OnGameStart() @@ -117,22 +118,34 @@ public class BackupCam : SonsMod _body = null; _screenGo = null; - foreach (var cart in Object.FindObjectsOfType()) - { - var body = cart.GetComponentInParent(); - if (body == null) body = cart.GetComponentInChildren(); - if (body == null || !IsInCart(body)) continue; + var player = LocalPlayer.Transform; + var root = player.root; + if (root != player && TryUseCart(root.GetComponentInChildren())) return true; - _cart = cart; - _body = body; - AttachCamera(); - AttachScreen(); - return true; + foreach (var col in Physics.OverlapSphere(player.position, SearchRadius, ~0, QueryTriggerInteraction.Ignore)) + { + if (col == null) continue; + if (TryUseCart(col.GetComponentInParent())) return true; } return false; } + bool TryUseCart(GolfCartController cart) + { + if (cart == null) return false; + + var body = cart.GetComponentInParent(); + if (body == null) body = cart.GetComponentInChildren(); + if (body == null || !IsInCart(body)) return false; + + _cart = cart; + _body = body; + AttachCamera(); + AttachScreen(); + return true; + } + bool IsInCart(Rigidbody body) { var player = LocalPlayer.Transform; diff --git a/manifest.json b/manifest.json index 13dcca3..effe311 100644 --- a/manifest.json +++ b/manifest.json @@ -3,7 +3,7 @@ "id": "BackupCam", "name": "BackupCam", "author": "JustinOros", - "version": "1.1.0", + "version": "1.1.1", "description": "Shows a backup camera when reversing the golf cart", "gameVersion": "1.0.0", "platform": "Client",