Ray Tracing
Unreal
void APlayerChar::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
FHitResult* Outhit;
float traceLimit = 100;
if(GetWorld()->LineTraceSingleByChannel(Outhit, GetComponentLocation(), GetForwardVector() * traceLimit, ECC_Visiblity)) { UE_LOG(LogTemp, Display, TEXT("%s"), *hitOut->GetName());
DrawDebugLine(GetWorld(), GetComponentLocation(), GetForwardVector() * traceLimit, FColor::Red, false, 1, 0, 5);//#include "DrawDebugHelpers.h"
}
}
Unity
void Update() {
RaycastHit hit;
float rayLimit = 100;
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, rayLimit)) { Debug.Log(hit.collider.gameObject.name);
Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hit.distance, Color.red);
}
}
Comments
Post a Comment