private static bool IsCustomLookAtTarget(MySmallShip smallShip, MyEntity otherEntity, float radius) { if (!MUST_LOOK_AT_TARGET) { return true; } BoundingSphere sphere = new BoundingSphere(otherEntity.WorldVolume.Center, radius); Ray ray = new Ray(smallShip.GetPosition(), smallShip.WorldMatrix.Forward); float? rayIntersection = ray.Intersects(sphere); if (rayIntersection.HasValue) { MyLine line = new MyLine(smallShip.WorldVolume.Center, otherEntity.WorldVolume.Center, true); MyIntersectionResultLineTriangleEx? result = MyEntities.GetIntersectionWithLine(ref line, smallShip, null, ignoreChilds: true); return !result.HasValue || !result.HasValue || result.Value.Entity == otherEntity; } return false; }
/// <summary> /// For debugging, add text to the debug screen which details the state of this bot. /// TODO: Move this to MyGuiScreenDebugBot. That class is specific to bot so this stuff could/should go there. /// </summary> /// <param name="bot">Computer-controlled ship.</param> /// <param name="player">The bot's target.</param> public static void AddToFrameDebugText(MySmallShipBot bot, MySmallShip player) { // Get a reference to the debug screen. MyGuiScreenDebugBot debugScreen = MyGuiManager.GetScreenDebugBot(); if (debugScreen != null) { // Here's the bot info we're adding to the debug screen text. debugScreen.AddToFrameDebugText("MyPhysObjectBot"); // Hello. debugScreen.AddToFrameDebugText(" Message: Hello!"); // Position. debugScreen.AddToFrameDebugText(" Player.Position: " + MyUtils.GetFormatedVector3(player.GetPosition(), 0)); // Offest between bot and player. Vector3 playerPos = player.GetPosition(); Vector3 botPos = bot.GetPosition(); Vector3 botToPlayer = botPos - playerPos; debugScreen.AddToFrameDebugText(" BotToPlayer: " + botToPlayer.ToString()); // Offest between player and bot. Vector3 playerToBot = playerPos - botPos; debugScreen.AddToFrameDebugText(" PlayerToBot: " + playerToBot.ToString()); // Bot forward Vector3 forward = bot.WorldMatrix.Forward; debugScreen.AddToFrameDebugText(" Bot.WorldMatrix.Forward: " + MyUtils.GetFormatedVector3(forward, 0)); // m_playersRelativePosition //debugScreen.AddToFrameDebugText(" Bot.m_playersRelativePosition: " + MyUtils.GetFormatedVector3(bot.Behavior.TargetsRelativePosition, 0)); // Aimed at player? //debugScreen.AddToFrameDebugText(" Bot.IsAimedAtPlayer: " + bot.IsBotPrettyMuchAimedAtPlayer()); // Distance to player. //debugScreen.AddToFrameDebugText(" Bot.DistanceToPlayer: " + ((int)(bot.DistanceTo(bot.Decision.Target))).ToString()); // Rotation indicator. //debugScreen.AddToFrameDebugText(" Bot.RotationIndicator: " + MyUtils.GetFormatedVector2(bot.RotationIndicator, 1)); // Blank line. debugScreen.AddToFrameDebugText(" "); } }
private bool IsPossibleTarget(MySmallShip smallShip, params object[] args) { if (!IsPotentialTarget(smallShip, args)) return false; MyLine testRay = new MyLine(m_gun.GetBarell().GetPosition(), smallShip.GetPosition(), false); Vector3? result = MyEntities.GetAnyIntersectionWithLine(ref testRay, this, smallShip, true, true, false, true); //smallShip.GetIntersectionWithLine(ref testRay, out result); return result == null; }
private bool IsPotentialTarget(MySmallShip smallShip, params object[] args) { if (MyFactions.GetFactionsRelation(GetOwner(), smallShip) != MyFactionRelationEnum.Enemy) { return false; } if (smallShip == MySession.PlayerShip && (Vector3.DistanceSquared(smallShip.GetPosition(), this.GetPosition()) > MyGameplayConstants.GameplayDifficultyProfile.LargeWeaponMaxAttackingDistanceForPlayer * MyGameplayConstants.GameplayDifficultyProfile.LargeWeaponMaxAttackingDistanceForPlayer)) return false; return true; }
void PushShip(MySmallShip detectedEntity, float distance, float influenceStrength) { var direction = detectedEntity.GetPosition() - this.GetPosition(); var directionNormalized = (1 / distance) * direction; float alignment = Vector3.Dot(directionNormalized, WorldMatrix.Up); alignment = MathHelper.Clamp(alignment, 0, 1); alignment = alignment * alignment * alignment; Debug.Assert(m_effectHelper.DirectionalPushStrength != null); detectedEntity.Physics.AddForce( MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, MyDummyPointConstants.PUSH_STRENGTH * m_effectHelper.DirectionalPushStrength.Value * alignment * influenceStrength * directionNormalized, detectedEntity.GetPosition(), Vector3.Zero); detectedEntity.IncreaseHeadShake(MyHeadShakeConstants.HEAD_SHAKE_AMOUNT_AFTER_SMOKE_PUSH * alignment * influenceStrength); }