protected override void Init_GotoTarget() { if (AiTargetBase.HasTarget()) { AiTargetBase.GotoTargetNoPath(0.0f); m_bot.Navigation.AimWithMovement(); } }
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); }