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"

CollisionBox for target selection within a certain radius?


The player should be able to select/switch throught targets near his character. e.g.: Player presses "TAB" and he will select the nearest target within a special radius around his character, without any height limit. So even if the the would be 10km above the target, if he is within this radius around his character he will be able to select the enemy.

Is a collision box the right approach for this?

Product Version: UE 4.7
more ▼

asked Jun 11 '15 at 06:48 PM in C++ Programming

avatar image

165 35 34 47

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

2 answers: sort voted first

If your player needs to get a single Actor above him a trace would suffice. You could easily just run a trace above your player and use the Hit Actor in your hit results. Whats not shown in this example is to switch between the targets. You could do this by doing a sphere trace for object instead of by channel and add the previously targeted actors to the ignore list. Heres the documentation page on traces (raycasts).

alt text

capture.png (104.9 kB)
more ▼

answered Jun 11 '15 at 07:21 PM

avatar image

686 15 13 128

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

(Posting this as an answer as comments cannot accept all my text...)

This question is posted in C++ so I assume op might be looking for a code solution as well as Blueprints.

I would implement it slightly differently in any case - according to op's specific requirements (Z axis difference should not affect the output), I would suggest implementing an interface on all targetable objects, and then to use an actor (or object) iterator to find the relevant targetable objects. Using an interface would speed up this query significantly.

After getting the list of targetable objects, you want to find the distance from the player to each of these, ignoring the Z component. This can be done as follows (I'm assuming the objects are actors for simplicity's sake):

     // I'm assuming you already
     TArray<Actor*> targetableActors = ...
     // Init closest actor
     AActor* closestActor = nullptr;
     // Only do if there are actually 
     if(targetableActors.Num() > 0)
         // Get character location
         FVector myLoc = GetActorLocation();
         // Use first actor as the closest one
         closestActor = targetableActors[0];
         float firstLoc = closestActor->GetActorLocation();    
         // Ignore Z-axis    
         firstLoc.Z = myLoc.Z;        
         // Calc first closest distance squared - we use squared as there's no need to root the distance for comparison purposes
         float closestDistSqrCurrent = FVector::DistSquared(myLoc, firstLoc);
         for(int32 i = 1; i < targetableActors.Num(); i++)
             // Get current targetable actor location
             FVector targetableActorLoc = targetableActors[i].GetActorLocation();
             // Ignore Z axis
             targetableActorLoc.Z = myLoc.Z;
             // Get squared distance from character to targetableActor
             float distSqr = FVector::DistSquared(myLoc, targetableActorLoc);
             if(distSqr < closestDist)
                 closestDistSqrCurrent = distSqr;
                 closestActor = targetableActors[i];
         // Do something with the closest actor
         const float closestDist = FMath::Sqrt(closestDistSqrCurrent);
         // there were no available actors...
more ▼

answered Jun 12 '15 at 10:24 AM

avatar image

2.6k 95 41 111

(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