Hello Guys! I have a problem with Line trace. When i activate it object is flying to camera component. It seems like Cursor somehow hits the camera and camera location becames end location of the trace, but i don’t know how to fix this. Actually I tried to change ECC_Visibility to ECC_Camera. or pawn. but it does not helps. Also i tried do smth with objects collision, and in some ways it works, but for objects of one class (for example desk) merges (collision is not working, and i really need this collision for objects).
On this gif you can actually see what is going on: https://giphy.com/gifs/linetrace-xUA7aPWCtONNCKa15S
Code of my Line trace:
void AObjectTemplate::PickupLineTrace() {
FHitResult *HitResultTrace = new FHitResult();
FVector StartLocation;
FVector EndLocation;
if (MyPC) {
FVector WorldMouseLocation;
FVector WorldMouseDirection;
UGameplayStatics::GetPlayerController(GetWorld(), 0)->DeprojectMousePositionToWorld(WorldMouseLocation, WorldMouseDirection);
WorldMouseDirection = WorldMouseDirection * 10000.0f;
StartLocation = WorldMouseLocation;
EndLocation = WorldMouseLocation + WorldMouseDirection;
FCollisionQueryParams TraceParams;
UE_LOG(LogTemp, Warning, TEXT("before line trace"));
if (GetWorld()->LineTraceSingleByChannel(*HitResultTrace, StartLocation, EndLocation, ECC_Camera, TraceParams)) {
SetActorLocation(HitResultTrace->Location);
}
UE_LOG(LogTemp, Warning, TEXT("after line trace"));
}
}
Code of camera component (in other class):
ACursorPawn::ACursorPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
AutoPossessPlayer = EAutoReceiveInput::Player0;
RootComponent = CreateDefaultSubobject<USceneComponent>(TEXT("RootComponent"));
//
MyCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("GameCamera"));
MyCamera->SetupAttachment(RootComponent);
MyCamera->SetRelativeRotation(FRotator(-90.0f, 0.0f, 0.0f));
CameraPanSpeed = -20.0f;
CameraRotationSpeed = -10.0f;
ZoomSpeed = -150.0f;
}