public static bool GenerateRaycast(out RaycastInfo info) { ItemGunAsset currentGun = OptimizationVariables.MainPlayer.equipment.asset as ItemGunAsset; float Range = currentGun?.range ?? 15.5f; info = GenerateOriginalRaycast(new Ray(OptimizationVariables.MainPlayer.look.aim.position, OptimizationVariables.MainPlayer.look.aim.forward), Range, RayMasks.DAMAGE_CLIENT); if (RaycastOptions.EnablePlayerSelection && TargetedPlayer != null) { GameObject p = TargetedPlayer.gameObject; bool shouldFire = true; Vector3 aimPos = OptimizationVariables.MainPlayer.look.aim.position; if (Vector3.Distance(aimPos, p.transform.position) > Range) { shouldFire = false; } if (!SphereUtilities.GetRaycast(p, aimPos, out Vector3 point)) { shouldFire = false; } if (shouldFire) { info = GenerateRaycast(p, point, info.collider); return(true); } if (RaycastOptions.OnlyShootAtSelectedPlayer) { return(false); } } if (!GetTargetObject(Objects, out GameObject Object, out Vector3 Point, Range)) { return(false); } info = GenerateRaycast(Object, Point, info.collider); return(true); }
public static bool GetTargetObject(HashSet <GameObject> Objects, out GameObject Object, out Vector3 Point, float Range) { double Distance = Range + 1; double FOV = 180; Object = null; Point = Vector3.zero; Vector3 AimPos = OptimizationVariables.MainPlayer.look.aim.position; Vector3 AimForward = OptimizationVariables.MainPlayer.look.aim.forward; foreach (GameObject go in Objects) { if (go == null) { continue; } Vector3 TargetPos = go.transform.position; Player p = go.GetComponent <Player>(); if (p && (p.life.isDead || FriendUtilities.IsFriendly(p))) { continue; } Zombie z = go.GetComponent <Zombie>(); if (z && z.isDead) { continue; } RaycastComponent Component = go.GetComponent <RaycastComponent>(); if (Component == null) { go.AddComponent <RaycastComponent>(); continue; } double NewDistance = VectorUtilities.GetDistance(AimPos, TargetPos); if (NewDistance > Range) { continue; } if (RaycastOptions.SilentAimUseFOV) { double _FOV = VectorUtilities.GetAngleDelta(AimPos, AimForward, TargetPos); if (_FOV > RaycastOptions.SilentAimFOV) { continue; } if (_FOV > FOV) { continue; } FOV = _FOV; } else if (NewDistance > Distance) { continue; } if (!SphereUtilities.GetRaycast(go, AimPos, out Vector3 _Point)) { continue; } Object = go; Distance = NewDistance; Point = _Point; } return(Object != null); }