Apexx 60 Posted November 13, 2018 Share Posted November 13, 2018 Hi, I am having problems understanding IsBehind. I would like to check if there are any mobs behind me. I am trying to add a backpedal feature to my fight class, but I don't think I am getting it correct. Here's what I tried: var EnemiesBehind = new List<WoWUnit>(); EnemiesBehind.AddRange(ObjectManager.GetWoWUnitHostile().Where( u => u.IsValid && !u.InCombat && u.IsAlive && u.IsBehind(Player.Position, 180.0f) && u.GetDistance <= Settings.BackpedalScanRange).OrderBy( o => ObjectManager.Me.Position.DistanceTo(o.Position))); if (EnemiesBehind != null && EnemiesBehind.Count > 0) { MyFunctions.LogDebug("Enemy, (" + EnemiesBehind.FirstOrDefault().Level + ")" + EnemiesBehind.FirstOrDefault().Name + " found behind you, skipping backpedal!"); Var.SetVar("CanBack", false); return; } Any help is much appreciated! Thank you! Image Reference: Link to comment https://wrobot.eu/forums/topic/10385-check-for-hostiles-units-behind-player/ Share on other sites More sharing options...
Apexx 60 Posted November 15, 2018 Author Share Posted November 15, 2018 I may have something here if anyone is interested. It still needs more testing though. Code: private void FightEventsOnFightStart(WoWUnit wowUnit, CancelEventArgs cancelable) { try { if (Settings.Backpedal) Var.SetVar("CanBack", true); } catch (Exception ex) { MyFunctions.LogWrite("FightEventsOnFightStart() Exception:" + Environment.NewLine + ex.ToString(), true); } } private async void FightEventsOnFightLoop(WoWUnit wowUnit, CancelEventArgs cancelable) { Random _rand = new Random(); bool _playerAggro = false; bool _playerStuck = false; #region Backpedal if (Settings.Backpedal && // Make sure Include Backpedal is TRUE in Settings (!Player.IsPartyMember || ObjectManager.Me.IsInGroup) && // Let's not backpedal in groups! Var.Exist("CanBack") && // Make sure our Variable exists Var.GetVar<bool>("CanBack") && // Make sure the Variable is TRUE Player.InCombat && // Make sure Player is in combat !Player.IsIndoors && // Skip if Player is indoor !Player.IsCast && // Make sure the Player is NOT casting Target.IsAlive && // Make sure the Target is valid Target.IsTargetingMe && // Make sure the Unit is Targeting the player !wowUnit.IsCast && // We don't want to backpedal from a casting target! MyFunctions.TargetInCooldownLevelRange()) // Target level is > Settings CD lvl { try { // Player.IsFacing(Vector3 targetPosition, [float arcRadians = 0.2]) // Player.IsFacing(u.Position, 1.5f) // 1.5 radians = 85.9 degrees || Arc Length = 37.5yd || Sector Area = 468.75 yd^2 var EnemiesInFrontPlayerNearTarget = ObjectManager.GetWoWUnitHostile().Where(u => u.IsValid && u.IsAlive && !u.InCombat && Player.IsFacing(u.Position, 1.5f) && Player.Target != u.GetBaseAddress && u.Position.DistanceTo(Target.Position) <= Settings.BackpedalScanRadius && (u.Reaction == Reaction.Hated || u.Reaction == Reaction.Hostile || u.Reaction == Reaction.Unfriendly)).OrderBy(o => Player.Position.DistanceTo(o.Position)).ToList(); var EnemiesBehindPlayer = ObjectManager.GetWoWUnitHostile().Where(u => u.IsValid && u.IsAlive && !u.InCombat && !Player.IsFacing(u.Position, 1.5f) && Player.Target != u.GetBaseAddress && u.Position.DistanceTo(Player.Position) <= (Settings.BackpedalScanRadius + (Settings.BackpedalScanRadius / 2)) && (u.Reaction == Reaction.Hated || u.Reaction == Reaction.Hostile || u.Reaction == Reaction.Unfriendly)).OrderBy(o => Player.Position.DistanceTo(o.Position)).ToList(); if (EnemiesInFrontPlayerNearTarget != null && EnemiesInFrontPlayerNearTarget.Count > 0) { foreach (WoWUnit unit in EnemiesInFrontPlayerNearTarget.Take(3)) { MyFunctions.LogDebug("Backpedal -> Enemy (Front): " + unit.Level + "-" + unit.Name + " (Distance: " + System.Math.Round(Player.Position.DistanceTo(unit.Position), 3) + "yd"); } WoWUnit NearestFrontUnit = EnemiesInFrontPlayerNearTarget.FirstOrDefault(); if (EnemiesBehindPlayer != null && EnemiesBehindPlayer.Count < 1) { var timer = new robotManager.Helpful.Timer(_rand.Next(3000, 4000)); var timerCheckDistance = new robotManager.Helpful.Timer(_rand.Next(1500, 2250)); Vector3 PlayerStartPos = Player.Position; int EnemyCountBegin = MyFunctions.HostileUnitsInRange(100.0f); MyFunctions.LogDebug("Backpedal -> Found no enemies behind you. Begin Backpedal"); if (wowUnit != NearestFrontUnit && !_playerAggro) { Move.Backward(Move.MoveAction.DownKey); while (!_playerStuck && (!timer.IsReady || wowUnit.Position.DistanceTo(NearestFrontUnit.Position) <= Settings.BackpedalScanRadius)) { if (Player.GetMove && wowUnit.IsCast) { MyFunctions.LogDebug("Backpedal -> Your target is casting; Stopping movement"); Var.SetVar("CanBack", false); break; } if (MyFunctions.HostileUnitsInRange(100.0f) != EnemyCountBegin) { MyFunctions.LogDebug("Backpedal -> Enemy count changed, you may have aggro'd something; Stopping movement"); Var.SetVar("CanBack", false); break; } if (timerCheckDistance.IsReady && Player.Position.DistanceTo(PlayerStartPos) < 1) just over a 1.5 sec. { MyFunctions.LogDebug("Backpedal -> Player might be stuck; Stopping movement"); _playerStuck = true; Var.SetVar("CanBack", false); break; } if (Player.Position.DistanceTo(NearestFrontUnit.Position) > Settings.BackpedalScanRadius) { MyFunctions.LogDebug("Backpedal -> Distance is greater than " + Settings.BackpedalScanRadius + " yards; Stopping movement"); Var.SetVar("CanBack", false); break; } if (Settings.BackpedalScanRadius > 0 && Player.Position.DistanceTo(PlayerStartPos) > Settings.BackpedalScanRadius) { MyFunctions.LogFight("Backpedal -> Player has moved more than " + Settings.BackpedalScanRadius + " yards; Stopping movement"); Var.SetVar("CanBack", false); break; } if (TraceLine.TraceLineGo(wowUnit.Position)) { MyFunctions.LogFight("Backpedal -> Your target is out of line of sight; Stopping movement"); Var.SetVar("CanBack", false); break; } Thread.Sleep(100); return; } } } else if (EnemiesBehindPlayer != null && EnemiesBehindPlayer.Count > 0) { foreach (WoWUnit unit in EnemiesBehindPlayer) { MyFunctions.LogDebug("Backpedal -> Enemy (Back): " + unit.Level + "-" + unit.Name + " (Distance: " + System.Math.Round(Player.Position.DistanceTo(unit.Position), 3) + "yd"); } MyFunctions.LogDebug("Backpedal -> Skipping movement"); Var.SetVar("CanBack", false); return; } } } catch (Exception ex) { MyFunctions.LogWrite("FightEventsOnFightLoop -> Backpedal Exception:" + Environment.NewLine + ex.ToString(), true); } } } Pudge 1 Link to comment https://wrobot.eu/forums/topic/10385-check-for-hostiles-units-behind-player/#findComment-49321 Share on other sites More sharing options...
Droidz 2742 Posted November 16, 2018 Share Posted November 16, 2018 Hello, you need to use IsBehind like that: u.IsBehind(ObjectManager.Me.Position, ObjectManager.Me.Rotation); ObjectManager.Me.IsBehind(u.Position, u.Rotation); you can also use: MovementManager.IsFacing(Me.Position, Me.Rotation, u.Position, 2.20f) p3tr0s, Pudge, Matenia and 1 other 3 1 Link to comment https://wrobot.eu/forums/topic/10385-check-for-hostiles-units-behind-player/#findComment-49335 Share on other sites More sharing options...
Apexx 60 Posted November 17, 2018 Author Share Posted November 17, 2018 Hey @Droidz thank you again! Link to comment https://wrobot.eu/forums/topic/10385-check-for-hostiles-units-behind-player/#findComment-49372 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now