Announcement

Collapse
No announcement yet.

Replacement or better method for Pawn.ReachedDestination(dest)?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Replacement or better method for Pawn.ReachedDestination(dest)?

    In UE3 I used Pawn.ReachedDestination() within the AI to check if I need to move the pawn to the next destination.

    Is there a new or different way to do this now. My custom method isn't working too well?

    #2
    Currently it's available only for path following, as it uses various properties of moving agent and goal. Please check HasReached* functions of PathFollowingComponent, although in most cases you shouldn't worry about calling them manually.

    While path is usually obtained from navigation system and regular path finding algorithms on navmesh or any other existing navigation data, it doesn't mean that you can't use it for simple movement to destination point in straight line. Check MoveToLocation/MoveToActor function in AIController for details (bUsePathfinding param).

    Comment


      #3
      Thanks a lot, my Actors have a collection of RouteObjects, which is an array of actor. I then iterate through this to move actors in a patrol route. The issue is that I need to check when they have reached a point on their patrol, really just calculating the differences in distance like this:

      Code:
      FVector targetVector = currentRouteObject->GetActorLocation();
      		FVector botVector = Bot->GetActorLocation();
      		static float DistSq = FVector().Dist(targetVector, botVector);
      
      		if ((botVector.X - targetVector.X) < 20 || (botVector.Z - targetVector.Z) < 10)

      Comment


        #4
        If we're talking about pawns controlled by AIController, easiest way would be requesting movement to next patrol point (MoveToActor) after completing previous move request. You can get this event in couple of ways: override AIController.OnMoveCompleted, use ReceiveMoveCompleted in blueprint, or use behavior tree tasks (There is a description for random wandering behavior, could be easily adapted for patrol: https://forums.unrealengine.com/show...nding-basic-AI).

        If those actor are being moved in some other, custom way - you'll need to figure it out on your own. If moving actors and goal are using cylinder collisions (should be if they are humanoids, could be if they are just points in space) you can improve being close condition by splitting test into 2 parts: 2D distance check + height difference check. Something along this lines:

        Code:
        float BotRadius = 0.0f, BotHalfHeight = 0.0f;
        float GoalRadius = 0.0f, GoalHalfHeight = 0.0f;
        
        currentRouteObject->GetSimpleCollisionCylinder(GoalRadius, GoalHalfHeight);
        Bot->GetSimpleCollisionCylinder(BotRadius, BotHalfHeight);
        
        const float Dist2DThresholdSq = FMath::Square(BotRadius + GoalRadius + some_value_for_2d_accuracy_lets_say_10);
        const float Dist2DSq = (targetVector - botVector).SizeSquared2D();
        const bool bReachedDist2D = (Dist2DSq <= Dist2DThresholdSq);
        
        const float BotGroundZ = botVector.Z - BotHalfHeight;
        const float GoalGroundZ = targetVector.Z - GoalHalfHeight;
        const float ZDiff = FMath::Abs(BotGroundZ - GoalGroundZ);
        const bool bReachedZ = (ZDiff < some_value_for_height_accuracy_lets_say_10);
        
        if (bReachedDist2D && bReachedZ)
        {
          // move to next point
        }
        However, I'd strongly suggest to use AIController's functions for this, as it allows to do stuff much quicker and handles all reachability tests by itself.

        Comment


          #5
          Thanks I'll give that a go

          Comment


            #6
            Thanks you fixed it

            it now waits until it canMove like so:

            Code:
            void ABaseAIController::OnMoveCompleted(uint32 RequestID, EPathFollowingResult::Type Result)
            {
            	if (Result == EPathFollowingResult::Success && target == currentRouteObject)
            	{
            		canMove = true;
            	}
            }
            
            void ABaseAIController::goToNextPathObject()
            {
            	if (currentRouteObject)
            	{
            		if (canMove)
            		{
            			setNextRouteObject();
            			canMove = false;
            			target = currentRouteObject;
            			moveToTarget();
            		}
            	}
            	else
            	{
            		currentRouteObject = Bot->PathObjects[0];
            		target = currentRouteObject;
            		moveToTarget();
            	}
            }

            Comment

            Working...
            X