MoveToLocation does not move pawn to the destination.

I’m trying to get an NPC to just move to a random location within the NavMesh after giving it an item (like a coffee cup). However, upon doing this the NPC starts moving sideways instead of directly to the random location. It even sometimes ends up outside of the navmesh.

Here is the code for a custom task where I move the NPC to a random location:

FNavLocation Location;
				if(NavSys->GetRandomPointInNavigableRadius(Origin, SearchRadius, Location))
				{
					OwnerComp.GetBlackboardComponent()->SetValueAsVector(FName("TargetLocation"), Location.Location);
					Cont->MoveToLocation(Location.Location);
					
				}

Here is the code for my other custom task where I give item to NPC:

	if(Cast<ACPP_NPCBase>(Cont->GetPawn()))
		{
			ACPP_NPCBase* NPC = Cast<ACPP_NPCBase>(Cont->GetPawn());
			OwnerComp.GetBlackboardComponent()->SetValueAsVector(FName("TargetLocation"), FVector(375.0, -90.0, NPC->GetActorLocation().Z));
			Cont->MoveToLocation(FVector(375.0, -90.0, NPC->GetActorLocation().Z));
			NPC->WantedItem = "Espresso";
		}
		

Here’s my behavior tree:

One thing to note is that if I disconnect the task where I give the item in the behavior tree, the NPC moves around properly. I don’t know why this happens however and would like some pointers! Thanks in advance :slight_smile:

Haha so, I figured out why it was moving weirdly. It was because the given item was somehow too close to the NPC, causing it to move strangely. I moved it away and it works fine now. I’m not too sure why it does so, but I’m going to assume maybe the collision gets messed up.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.