x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

AI following a spline

Hi, I would like to make my AI follow a spline while still using the navmesh and detour avoidance.

I came up with a solution that I didn't implement yet since I'm not sure if it's correct or if there's already a better one, so just for the sake of it I'm asking first before potentially throwing my work away :) Namely the solution consists of creating an invisible Actor that follows the spline and then setting that actor as a move target for my AI.

My main concern is if detour will still work correctly when the target is not far enough from the AI or what would happen if the target suddenly finds itself inside a dynamic collision while the real target (end of spline) is still reachable and unobstructed.

Thanks in advance.

Product Version: Not Selected
Tags:
more ▼

asked Oct 20 '14 at 02:09 PM in C++ Programming

avatar image

Marek
33 5 11 16

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hi Marek,

There's currently no out-of-the-box way to do what you describe. In general the solution you described would work, with caveats:

  • having AI follow an actor that constantly changes location will result in repathing every "threshold" distance covered by followed actor

  • every repath can result in totally different path, which in turn might defeat your purpose and result in sharp turns

  • you'd need to influence virtual-goal-actor's movement to stay as more or less same distance of the AI following it, to guarantee "stable" result

But give your solution a try none the less, you're bound to learn something! :D

The proper solution would be to implement custom PathFollowingComponent (that tells CharacterMovementComponent where it should go) or custom CharacterMovementComponent (to adjust what PathFollowingComponent is telling it), and just handle sudden move direction changing, smoothing it out.

There are some far plans to do that on the AIModule level, but not anytime soon. Sorry!

Cheers,

--mieszko

more ▼

answered Oct 20 '14 at 09:38 PM

avatar image

MieszkoZ STAFF
7.3k 223 57 412

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I am not 100% sure what you are trying to accomplish but maybe this will help:

     APawn* MyBot = MyController->GetPawn();
     AMyCharacter* FollowTarget = MyController->GetTarget();
     if (Enemy && MyBot)
     {
         const float SearchRadius = 200.0f;
         const FVector SearchOrigin = FollowTarget->GetActorLocation() + 600.0f * (MyBot->GetActorLocation() - FollowTarget->GetActorLocation()).SafeNormal();
         const FVector Loc = UNavigationSystem::GetRandomPointInRadius(MyController, SearchOrigin, SearchRadius);
         if (Loc != FVector::ZeroVector)
         {
             MyComp->GetBlackboardComponent()->SetValueAsVector(BlackboardKey.GetSelectedKeyID(), Loc);
             return EBTNodeResult::Succeeded;
         }
     }
  
     return EBTNodeResult::Failed;
 }

This will have the AI basically look for whatever target you want him to follow. It will then pick a random point near that target and save that location into a BlackBoard Component. Then you can tell the pawn to simply move to that location. This is dynamic path finding. This is how enemy bots find and move to the player in the ShooterGame example. I tweaked the code to suite my needs, perhaps you could do the same.

more ▼

answered Oct 20 '14 at 05:20 PM

avatar image

Janyx
492 66 65 211

avatar image Marek Oct 20 '14 at 06:35 PM

Hi, thanks for your answer but that's not what I ment. What i want to achieve is an NPC following a spline (curve) that I place on the level as a SplineComponent. I need this to make them patrol more naturally without making hard turns after reaching certain point.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question