-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStaticMeshTurnAnomaly.cpp
More file actions
114 lines (80 loc) · 2.97 KB
/
StaticMeshTurnAnomaly.cpp
File metadata and controls
114 lines (80 loc) · 2.97 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Fill out your copyright notice in the Description page of Project Settings.
#include "StaticMeshTurnAnomaly.h"
#include "Engine/StaticMesh.h"
#include "Kismet/KismetMathLibrary.h"
#include "Camera/CameraActor.h"
#include "Kismet/GameplayStatics.h"
#include "TimerManager.h"
AStaticMeshTurnAnomaly::AStaticMeshTurnAnomaly()
{
PrimaryActorTick.bCanEverTick = true;
MeshComponent = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("MeshComponent"));
RootComponent = MeshComponent;
}
void AStaticMeshTurnAnomaly::BeginPlay()
{
Super::BeginPlay();
InitialRotation = GetActorRotation();
MeshComponent->SetVisibility(false);
// Log the initial rotation
UE_LOG(LogTemp, Warning, TEXT("Initial Rotation: %s"), *InitialRotation.ToString());
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ACameraActor::StaticClass(), FoundActors);
// Log the number of found actors
UE_LOG(LogTemp, Warning, TEXT("Found %d camera actors."), FoundActors.Num());
for (AActor* Actor : FoundActors)
{
// Log each actor's name
UE_LOG(LogTemp, Warning, TEXT("Found Actor: %s"), *Actor->GetName());
if (Actor->GetName() == "BP_Cam3_C_UAID_D843AE24536DC62202_1266467247")
{
TargetCamera = Cast<ACameraActor>(Actor);
if (TargetCamera)
{
UE_LOG(LogTemp, Warning, TEXT("Target Camera found: %s"), *TargetCamera->GetName());
}
else
{
UE_LOG(LogTemp, Error, TEXT("Failed to cast to ACameraActor for actor: %s"), *Actor->GetName());
}
break;
}
}
if (!TargetCamera)
{
UE_LOG(LogTemp, Error , TEXT("No target camera found with the name BP_Cam3."));
}
UE_LOG(LogTemp, Error, TEXT("Mesh Visibility: %s"), MeshComponent->IsVisible() ? TEXT("Visible") : TEXT("Hidden"));
}
void AStaticMeshTurnAnomaly::RotateToFaceCamera()
{
if(TargetCamera)
{
FVector CameraLocation = TargetCamera->GetActorLocation();
FVector DirectionToCamera = CameraLocation - GetActorLocation();
DirectionToCamera.Normalize();
FRotator NewRotation = DirectionToCamera.Rotation();
SetActorRotation(NewRotation);
UE_LOG(LogTemp, Warning, TEXT("Rotating to face camera"));
}
else
{
UE_LOG(LogTemp, Warning, TEXT("TargetCamera is not set"));
}
}
void AStaticMeshTurnAnomaly::TriggerAnomaly()
{
MeshComponent->SetVisibility(true);
GetWorld()->GetTimerManager().SetTimer
(TimerHandle, this, &AStaticMeshTurnAnomaly::RotateToFaceCamera, 3.0f, false);
UnfixedAnamolyCount++;
}
void AStaticMeshTurnAnomaly::FixAnomaly()
{
MeshComponent->SetVisibility(false);
UnfixedAnamolyCount--;
}
void AStaticMeshTurnAnomaly::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}