Hi, i'm currently working on a small game in which you redirect line traces in order to bounce them on certain objects until it reaches the end point.
What i need help with is the actual calculation of what direction the reflected line trace needs to have.
This is my code at the moment.
So i'm wondering if unreal engine 4 have some inbuilt function for this or do i need to do the math myself and if so, anyone have any suggestions or math examples for me to take a look at?
Thanks!
// Solicio
What i need help with is the actual calculation of what direction the reflected line trace needs to have.
This is my code at the moment.
Code:
UWorld* TheWorld = this->GetWorld(); FColor debugColor = FColor::Red; FHitResult HitResult(ForceInit); FVector StartFVector = this->GetActorLocation(); FVector EndFVector = StartFVector + GetActorForwardVector() * RayLength; FCollisionQueryParams TraceParams(TEXT("MyTrace"), true, this); TraceParams.bTraceComplex = true; TraceParams.bTraceAsyncScene = true; TraceParams.bReturnPhysicalMaterial = false; if (TheWorld->LineTraceSingle(HitResult, StartFVector, EndFVector, ECC_WorldStatic, TraceParams)) { DrawDebugLine(TheWorld, StartFVector, HitResult.Location, debugColor, false, 30.0f, 1.0f, 3.0f); if (HitResult.GetActor()) { if (HitResult.GetActor()->ActorHasTag("Reflect")) { // Calculate and create ray for the reflected line trace StartFVector = HitResult.Location; EndFVector = StartFVector + !Direction Of New Ray! * RayLength; if (TheWorld->LineTraceSingle(HitResult, StartFVector, EndFVector, ECC_WorldStatic, TraceParams)) { DrawDebugLine(TheWorld, StartFVector, HitResult.Location, FColor::Green, false, 30.0f, 1.0f, 3.0f); } else { DrawDebugLine(TheWorld, StartFVector, EndFVector, FColor::Blue, false, 30.0f, 1.0f, 3.0f); } //GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Reflected")); } } }
Thanks!
// Solicio
Comment