protected MyBehaviorTreeState RunAway()
 {
     if (m_bot.Navigation.Navigating)
     {
         if (m_bot.Navigation.Stuck)
         {
             if (m_usingPathfinding)
             {
                 return(MyBehaviorTreeState.FAILURE);
             }
             else
             {
                 m_usingPathfinding = true;
                 AnimalLogic.EnableCharacterAvoidance(false);
                 AiTargetBase.GotoTarget();
                 return(MyBehaviorTreeState.RUNNING);
             }
         }
         else
         {
             return(MyBehaviorTreeState.RUNNING);
         }
     }
     else
     {
         return(MyBehaviorTreeState.SUCCESS);
     }
 }
        protected MyBehaviorTreeState FindRandomSafeLocation([BTIn] ref MyBBMemoryTarget inTargetEnemy, [BTOut] ref MyBBMemoryTarget outTargetLocation)
        {
            if (inTargetEnemy == null || !inTargetEnemy.EntityId.HasValue)
            {
                return(MyBehaviorTreeState.FAILURE);
            }
            MyEntity targetEntity = null;

            if (MyEntities.TryGetEntityById(inTargetEnemy.EntityId.Value, out targetEntity))
            {
                Vector3D botPosition    = m_bot.AgentEntity.PositionComp.GetPosition();
                Vector3D directionToBot = botPosition - targetEntity.PositionComp.GetPosition();
                directionToBot.Normalize();

                Vector3D safeLocation = default(Vector3D);
                if (!AiTargetBase.GetRandomDirectedPosition(botPosition, directionToBot, out safeLocation))
                {
                    safeLocation = botPosition + directionToBot * 30;
                }

                MyBBMemoryTarget.SetTargetPosition(ref outTargetLocation, safeLocation);
                return(MyBehaviorTreeState.SUCCESS);
            }
            else
            {
                return(MyBehaviorTreeState.FAILURE);
            }
        }
 public MyBehaviorTreeState GotoAndAimTarget(float rotationAngle = 2)
 {
     if (!AiTargetBase.HasTarget())
     {
         return(MyBehaviorTreeState.FAILURE);
     }
     if (Bot.Navigation.Navigating)
     {
         if (Bot.Navigation.Stuck)
         {
             return(MyBehaviorTreeState.FAILURE);
         }
         else
         {
             return(MyBehaviorTreeState.RUNNING);
         }
     }
     else if (Bot.Navigation.HasRotation(MathHelper.ToRadians(rotationAngle)))
     {
         return(MyBehaviorTreeState.RUNNING);
     }
     else
     {
         return(MyBehaviorTreeState.SUCCESS);
     }
 }
Example #4
0
 public void Init_AimAtTarget()
 {
     if (AiTargetBase.HasTarget())
     {
         AiTargetBase.AimAtTarget();
     }
 }
 protected override void Init_GotoTarget()
 {
     if (AiTargetBase.HasTarget())
     {
         AiTargetBase.GotoTargetNoPath(0.0f);
         m_bot.Navigation.AimWithMovement();
     }
 }
 public void Init_GotoAndAimTarget()
 {
     if (AiTargetBase.HasTarget())
     {
         AiTargetBase.GotoTarget();
         AiTargetBase.AimAtTarget();
     }
 }
Example #7
0
        protected MyBehaviorTreeState RunAway([BTParam] float distance)
        {
            if (!runAwayPos.HasValue)
            {
                Vector3D currentPosition  = Bot.Player.Character.PositionComp.GetPosition();
                Vector3D planetGravityVec = MyGravityProviderSystem.CalculateNaturalGravityInPoint(currentPosition);

                var planet = MyGravityProviderSystem.GetNearestPlanet(currentPosition);
                if (planet == null)
                {
                    return(MyBehaviorTreeState.FAILURE);
                }

                if (lastTargetedEntityPosition.HasValue)
                {
                    Vector3D lastTargetedEntityPositionProjected = lastTargetedEntityPosition.Value;
                    lastTargetedEntityPositionProjected = planet.GetClosestSurfacePointGlobal(ref lastTargetedEntityPositionProjected);

                    Vector3D direction           = currentPosition - lastTargetedEntityPositionProjected;
                    Vector3D runAwayPosCandidate = currentPosition + Vector3D.Normalize(direction) * distance;
                    runAwayPos = planet.GetClosestSurfacePointGlobal(ref runAwayPosCandidate);
                }
                else
                {
                    planetGravityVec.Normalize();
                    Vector3D planetTangent   = Vector3D.CalculatePerpendicularVector(planetGravityVec);
                    Vector3D planetBitangent = Vector3D.Cross(planetGravityVec, planetTangent);
                    planetTangent.Normalize();
                    planetBitangent.Normalize();
                    Vector3D runAwayPosCandidate = MyUtils.GetRandomDiscPosition(ref currentPosition, distance, distance, ref planetTangent, ref planetBitangent);
                    if (planet != null)
                    {
                        runAwayPos = planet.GetClosestSurfacePointGlobal(ref runAwayPosCandidate);
                    }
                    else
                    {
                        runAwayPos = runAwayPosCandidate;
                    }
                }
                AiTargetBase.SetTargetPosition(runAwayPos.Value);
                AimWithMovement();
            }
            else
            {
                if (Bot.Navigation.Stuck)
                {
                    return(MyBehaviorTreeState.FAILURE);
                }
            }

            AiTargetBase.GotoTargetNoPath(1.0f, false);

            if (Vector3D.DistanceSquared(runAwayPos.Value, Bot.Player.Character.PositionComp.GetPosition()) < 10.0f * 10.0f)
            {
                CyberhoundLogic.Remove();
                return(MyBehaviorTreeState.SUCCESS);
            }
            else
            {
                return(MyBehaviorTreeState.RUNNING);
            }
        }
 protected void Init_RunAway()
 {
     AnimalLogic.EnableCharacterAvoidance(true);
     m_bot.Navigation.AimWithMovement();
     AiTargetBase.GotoTargetNoPath(0.0f);
 }