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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Is my ray casting / line tracing wrong?

Hello, it's me again.

Code: FCollisionQueryParams Params; // Ignore the player's pawn

     // The hit result gets populated by the line trace
     FHitResult Hit;

     // Raycast out from the camera, only collide with pawns (they are on the ECC_Pawn collision channel)
     FVector Start = thruster->GetComponentLocation();
     FVector End = Start +  (thruster->GetUpVector() * (traceLength*-1));
     bool bHit = GetWorld()->LineTraceSingleByChannel(Hit, Start, End, ECC_Pawn, Params);

     if (bHit)
         // Hit.Actor contains a weak pointer to the Actor that the trace hit
         FVector step1 = Hit.Location - thruster->GetComponentLocation();
         float vectorLength = step1.Size();
         float alpha = vectorLength / traceLength;
         float step2 = FMath::Lerp(hoverForce, 0.0f, alpha);
         FVector downwardForce = Hit.ImpactNormal * step2;
         //StaticMeshComponent->AddForceAtLocation(FVector(0, 0, 1) * hoverForce *(1.0f - (Hit.Distance / traceLength)), thruster->GetComponentLocation());
         StaticMeshComponent->AddForceAtLocation(downwardForce, thruster->GetComponentLocation());

         compressionRatio = alpha;
         surfaceImpactNormal = Hit.ImpactNormal;
         surfaceImpactPoint = Hit.ImpactPoint;

The problem is my trace length and debug differs.

If you look at the first picture my trace length is going through the ground. No I don't want that, I want it to touch the ground, and then push me up.

alt text I am in mid - air and my trace length (the yellow lines) are way longer.

![alt text][2] Have I implemented the ray cast wrong?

Product Version: UE 4.9
u1.png (53.9 kB)
untitled2.png (318.5 kB)
untitled2.png (318.5 kB)
more ▼

asked Feb 11 '16 at 05:29 PM in C++ Programming

avatar image

219 19 17 24

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

0 answers: sort voted first
Be the first one to answer this question
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