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