[ Unreal Engine 5 C++ Developer: Learn C++ & Make Video Games]
[4) Line Tracing & Sweeping]
Grabber.cpp
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
FRotator getRotation = GetComponentRotation();
FString getstring = getRotation.ToCompactString();
// UE_LOG(LogTemp, Display, TEXT("Grabber Rotation: %s"), *getstring);
UWorld* World = GetWorld();
float Time = World->TimeSeconds;
// float Time = getWorld()->TimeSeconds; // We can use as well
//UE_LOG(LogTemp, Display, TEXT("Show Turrent Time: %f"), Time);
/// hew we try to Draw Debug Line; Ok
FVector Start = GetComponentLocation();
FVector End = Start + GetForwardVector() * MaxGrabDistance;
DrawDebugLine(GetWorld(), Start, End, FColor::Red);
}
void UGrabber::Release()
{
UE_LOG(LogTemp, Error, TEXT("Release Grabber"))
}
void UGrabber::Grabes()
{
UE_LOG(LogTemp,Warning,TEXT("Grabber"))
/// hew we try to Draw Debug Line; Ok
FVector Start = GetComponentLocation();
FVector End = Start + GetForwardVector() * MaxGrabDistance;
//DrawDebugLine(GetWorld(), Start, End, FColor::Red);
FCollisionShape spheer = FCollisionShape::MakeSphere(GrabRadius);
/// Hear we try to to trace line(hit object Name)
FHitResult HitResult;
bool HasHit = GetWorld()->SweepSingleByChannel(
HitResult, Start, End,
FQuat::Identity, ECC_EngineTraceChannel2,
spheer);
if (HasHit)
{
FString str = HitResult.GetActor()->GetActorLabel();
AActor* HitActor = HitResult.GetActor();
UE_LOG(LogTemp,Warning, TEXT("%s"), *HitActor->GetName());
}
else
{
UE_LOG(LogTemp,Warning, TEXT("No object Hit"));
}
}
this problem currently I am fasting can any one can tell me why?
FVector Start = GetComponentLocation() * 5; // I try this but It's crash my Engine (Why crash )
How can I learn about all this concepts