I’m trying to translate Blueprint function into C++.
My Blueorint Function:
C++ code:
void ARPG_TutorialCharacter::VaultC()
{
for (int i = 0; i <= 2; i++) {
FVector TraceStart = GetActorLocation();
TraceStart.Z += i * 30;
FVector TraceEnd = UKismetMathLibrary::GetForwardVector(GetActorRotation());
TraceEnd *= 180.0;
TArray<AActor*, FDefaultAllocator> IgnoredActors;
FHitResult TraceResults;
bool OutHit = UKismetSystemLibrary::SphereTraceSingle(this, TraceStart, TraceEnd + TraceStart, 5.0, ETraceTypeQuery::TraceTypeQuery1, false, IgnoredActors, EDrawDebugTrace::ForDuration, TraceResults, true);
if (OutHit) {
for (int j = 0; j <= 5; j++) {
FVector SubTraceStart = TraceResults.Location + FVector(0.0, 0.0, 100.0);
FVector SubTraceEnd = UKismetMathLibrary::GetForwardVector(GetActorRotation());
SubTraceEnd *= j * 50;
if (UKismetSystemLibrary::SphereTraceSingle(this, SubTraceStart + SubTraceEnd, SubTraceStart + SubTraceEnd - FVector(0.0,0.0,100.0), 10.0, ETraceTypeQuery::TraceTypeQuery1, false, IgnoredActors, EDrawDebugTrace::ForDuration, TraceResults, true)) {
if (j == 0) {
}
}
}
break;
}
}
}
Problem is on lines
for (int j = 0; j <= 5; j++) {
FVector SubTraceStart = TraceResults.Location + FVector(0.0, 0.0, 100.0);
FVector SubTraceEnd = UKismetMathLibrary::GetForwardVector(GetActorRotation());
SubTraceEnd *= j * 50;
if (UKismetSystemLibrary::SphereTraceSingle(this, SubTraceStart + SubTraceEnd, SubTraceStart + SubTraceEnd - FVector(0.0,0.0,100.0), 10.0, ETraceTypeQuery::TraceTypeQuery1, false, IgnoredActors, EDrawDebugTrace::ForDuration, TraceResults, true)) {
if (j == 0) {
}
}
}
Spheres are created in incorrect positions. It seems to me that the problem is with the calculations