1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| void ABasePlayerController::TestDoCapsuleTrace(float StartZOffset, float EndZOffset, float InDistance) { float DuringTime = 50.f; ACharacter *pChar = GetCharacter(); FVector StartLocation = pChar->GetActorLocation();
FVector Forward = pChar->GetActorForwardVector().GetSafeNormal(); FVector Right = pChar->GetActorRightVector().GetSafeNormal(); StartLocation.Z += StartZOffset; FVector EndLocation = StartLocation + Forward*InDistance; EndLocation.Z += EndZOffset;
float ScaledCapsuleHalfHeight = pChar->GetCapsuleComponent()->GetScaledCapsuleHalfHeight(); float ScaledCapsuleRadius = pChar->GetCapsuleComponent()->GetScaledCapsuleRadius();
FCollisionQueryParams Params; Params.AddIgnoredActor(pChar); FName ProfilerName("MyTestProfiler");
UKismetSystemLibrary::DrawDebugLine(this, StartLocation, EndLocation, FLinearColor::Red, DuringTime); UKismetSystemLibrary::DrawDebugCapsule(this, StartLocation, ScaledCapsuleHalfHeight, ScaledCapsuleRadius, FRotator::ZeroRotator, FLinearColor::Blue, DuringTime); UKismetSystemLibrary::DrawDebugBox(this, StartLocation, FVector::OneVector, FLinearColor::Blue, FRotator::ZeroRotator, DuringTime); UKismetSystemLibrary::DrawDebugCapsule(this, EndLocation, ScaledCapsuleHalfHeight, ScaledCapsuleRadius, FRotator::ZeroRotator, FLinearColor::Blue, DuringTime); UKismetSystemLibrary::DrawDebugBox(this, EndLocation, FVector::OneVector, FLinearColor::Blue, FRotator::ZeroRotator, DuringTime);
FHitResult HitResult; bool bHit = GetWorld()->SweepSingleByProfile(HitResult, StartLocation, EndLocation, FQuat::Identity, ProfilerName, FCollisionShape::MakeCapsule(ScaledCapsuleRadius, ScaledCapsuleHalfHeight), Params); if (bHit) { if (HitResult.bBlockingHit) { UKismetSystemLibrary::DrawDebugBox(this, HitResult.Location, FVector::OneVector, FLinearColor::Blue, FRotator::ZeroRotator, DuringTime);
UKismetSystemLibrary::DrawDebugBox(this, HitResult.ImpactPoint, FVector::OneVector, FLinearColor::Blue, FRotator::ZeroRotator, DuringTime);
FVector BottomLocation = HitResult.Location; BottomLocation.Z = HitResult.Location.Z - ScaledCapsuleHalfHeight + ScaledCapsuleRadius; UKismetSystemLibrary::DrawDebugBox(this, BottomLocation, FVector::OneVector, FLinearColor::Blue, FRotator::ZeroRotator, DuringTime); UKismetSystemLibrary::DrawDebugLine(this, HitResult.Location, BottomLocation, FLinearColor::Green, DuringTime);
UKismetSystemLibrary::DrawDebugCapsule(this, HitResult.Location, ScaledCapsuleHalfHeight, ScaledCapsuleRadius, FRotator::ZeroRotator, FLinearColor::Red, DuringTime);
UKismetSystemLibrary::DrawDebugLine(this, HitResult.ImpactPoint, HitResult.ImpactPoint + HitResult.ImpactNormal * 100, FLinearColor::Green, DuringTime);
UKismetSystemLibrary::DrawDebugLine(this, HitResult.ImpactPoint, HitResult.ImpactPoint+ HitResult.Normal*100, FLinearColor::White, DuringTime);
} else { } } }
|