Advertisement
orfeasel

Single Line Trace

Dec 22nd, 2015
8,716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. void AFpCppCharacter::Tick(float DeltaTime)
  2. {
  3.     Super::Tick(DeltaTime);
  4.  
  5.     //Hit contains information about what the raycast hit.
  6.     FHitResult Hit;
  7.  
  8.     //The length of the ray in units.
  9.     //For more flexibility you can expose a public variable in the editor
  10.     float RayLength = 200;
  11.  
  12.     //The Origin of the raycast
  13.     FVector StartLocation = FirstPersonCameraComponent->GetComponentLocation();
  14.  
  15.     //The EndLocation of the raycast
  16.     FVector EndLocation = StartLocation + (FirstPersonCameraComponent->GetForwardVector() * RayLength);
  17.  
  18.     //Collision parameters. The following syntax means that we don't want the trace to be complex
  19.     FCollisionQueryParams CollisionParameters;
  20.  
  21.     //Perform the line trace
  22.     //The ECollisionChannel parameter is used in order to determine what we are looking for when performing the raycast
  23.     ActorLineTraceSingle(Hit, StartLocation, EndLocation, ECollisionChannel::ECC_WorldDynamic, CollisionParameters);
  24.  
  25.     //DrawDebugLine is used in order to see the raycast we performed
  26.     //The boolean parameter used here means that we want the lines to be persistent so we can see the actual raycast
  27.     //The last parameter is the width of the lines.
  28.     DrawDebugLine(GetWorld(), StartLocation, EndLocation, FColor::Green, true, -1, 0, 1.f);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement