Trace down 40 units below the objects position.


In the past I have attempted to make a hover car/ physics car with suspension mechanics in blue print and half managed to meet my solution.

I am not a visual scripter, since I come from a Unity/ As3 background.

In an attempt to line trace down via c++ UE4 library, I have first added four points to a static mesh.

These for points are added via code, and in the blue print I move them manually.

In my script I add all of these four points into an array.

TArray<USceneComponent*> hoverArray;



I then loop through the array and do a line trace to see if I am hitting 40 yards down.

	for (int32 b = 0; b < hoverArray.Num(); b++)
		const FName TraceTag("MyTraceTag");

		FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this);
		RV_TraceParams.bTraceComplex = true;
		RV_TraceParams.bTraceAsyncScene = true;
		RV_TraceParams.bReturnPhysicalMaterial = false;
		RV_TraceParams.TraceTag = TraceTag;
		//Re-initialize hit info
		FHitResult RV_Hit(ForceInit);
		FVector Start;// = FVector::ZeroVector;
		FVector End;// = FVector::ZeroVector;
		FVector GetUpVector = FVector::ZeroVector;

		Start = hoverArray**->GetComponentLocation();

		GetUpVector = hoverArray**->GetUpVector();

		GetUpVector = GetUpVector*(traceLength * -1);

		End = Start + GetUpVector;

		//End = hoverArray**->GetWorld + (hoverArray**->GetUpVector()*(traceLength*-1));

		//call GetWorld() from within an actor extending class
			RV_Hit,        //result
			Start,    //start
			End, //end
			ECC_Pawn, //collision channel

		RV_Hit.bBlockingHit; //did hit something? (bool)
		RV_Hit.GetActor(); //the hit actor if there is one
		RV_Hit.ImpactPoint;  //FVector
		RV_Hit.ImpactNormal;  //FVector

			FColor(255, 0, 0),
			false, -1, 0,

I’m guessing the problem is in the “End” Variable.

This is the result…

Can someone please tell me why the “End” point is not updating?

I could be wrong but to me it looks more like your DebugLineDrawing is “incorrect”/not what you are expecting. Your line goes from Start to RV_Hit.Location. RV_Hit.Location appears to be FVector::ZeroVector if the trace does not hit anything. Therefore your debug lines all go from start to the origin. You could either try to enable the built-in trace debug drawing (not sure where that is exactly, it’s available from Blueprint somewhere…) or check whether your trace hit anything and then decide whether to use RV_Hit.Location or simply End as the second point of the line.

The way you calculate End looks good to me.

UnrealEverything, thank you so much for the input.

I think my End is wrong,

			FColor(255, 0, 0),
			false, -1, 0,

This bloody draws the end of the line from the End.

And from testing, I found that my car only “hovers” when it goes to the “End” point.

It appears End is a constant, and not static/ dynamic.

When this is done in blue print it works.

I have tried a new method,

	FVector End = thruster-&gt;GetUpVector() *(traceLength*-1);

Yet same result lol.

In blue print this would work, I have no idea what Im doing wrong.

Maybe because this should be in a fixUpdate?

		FVector Start = thruster->GetComponentLocation();
		FVector End = Start + (thruster->GetUpVector() *(traceLength*-1));

		bool bHit = GetWorld()->LineTraceSingleByChannel(RV_Hit, Start, End, ECC_Pawn, RV_TraceParams);

Yes, i am an idiot.

Slowly getting there,

I am not sure If i should loop through the array of components, or do it individually?

What are your thoughts community?