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"

How to ray cast?

Hello, so i was just wondering how i can make a simple ray cast within UE4 say for like weapons or AI? also some examples would be great! i seen a few other posts but the answers weren't very clear so i was hoping to get some clarity with this :)

Product Version: Not Selected
more ▼

asked Oct 29 '14 at 06:46 PM in C++ Programming

avatar image

65 7 9 13

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

1 answer: sort voted first

You have a lot of that in GWorld:

  1. LineTraceTest - Trace a ray against the world using a specific channel and return if a blocking hit is found.

  2. LineTraceSingle - Trace a ray against the world using a specific channel and return the first blocking hit.

  3. LineTraceMulti - Trace a ray against the world using a specific channel and return overlapping hits and then first blocking hit. Results are sorted, so a blocking hit (if found) will be the last element of the array. Only the single closest blocking result will be generated, no tests will be done after that.


For example in Unreal Tournament, trace channels are defined in UnrealTournament.h.

 #define COLLISION_PROJECTILE ECC_GameTraceChannel1
 #define COLLISION_TRACE_WEAPON ECC_GameTraceChannel2
 #define COLLISION_PAWNOVERLAP ECC_GameTraceChannel5

And then used from many places such as: UTGameplayStatics::ComponentIsVisibleFrom(...).

 FCollisionQueryParams LineParams(FName(TEXT("ComponentIsVisibleFrom")), true, IgnoredActor);

 bool const bHadBlockingHit = World->LineTraceSingle(OutHitResult, TraceStart, TraceEnd, COLLISION_TRACE_WEAPON, LineParams);

Where TraceStart and TraceEnd are vectors, OutHitResult is an out parameter that have result of your hit test.


more ▼

answered Oct 29 '14 at 07:08 PM

avatar image

578 23 15 48

avatar image FortuneStudios Oct 29 '14 at 07:57 PM

hey thanks that was really helpful! so somthing like this would work?

  #define COLLISION_TRACE ECC_GameTraceChannel1
 FHistResult Hit;//the thing that is an output of the statement
 FCollisionQueryParams Line(FName("Collision param"),true);
 World->LineTraceSingle(Hit, this->Location /*cant remember the actual name for the variable :/ */, this->RelativeLocation.X += 100,COLLISION_TRACE,Line);
 AEnemy* enemy = Cast<AEnemy>(Hit.GetActor());
avatar image mpo Oct 29 '14 at 08:43 PM
avatar image FortuneStudios Oct 29 '14 at 09:04 PM

thank you very much for your help :) really appreciate it

avatar image mpo Nov 01 '14 at 03:48 PM

If you consider this answer as helpful, please close question so that thers will know that issue is solved. Marcin

(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