-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTrigger_Component.cpp
More file actions
62 lines (44 loc) · 1.64 KB
/
Trigger_Component.cpp
File metadata and controls
62 lines (44 loc) · 1.64 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
// Fill out your copyright notice in the Description page of Project Settings.
#include "Trigger_Component.h"
UTrigger_Component::UTrigger_Component() {
PrimaryComponentTick.bCanEverTick = true;
}
void UTrigger_Component::BeginPlay()
{
Super::BeginPlay();
// ...
}
void UTrigger_Component::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
AActor* Actor = GetAcceptableActor();
if (Actor!= nullptr) {
UE_LOG(LogTemp, Display, TEXT("Unlocking"));
UPrimitiveComponent* Component=Cast<UPrimitiveComponent>(Actor->GetRootComponent());//casting this pointer in to the uprimitive component because our actor does not know that it contain uprimitive component or not
if (Component != nullptr) {
Component->SetSimulatePhysics(false);
}
Actor->AttachToComponent(this, FAttachmentTransformRules::KeepWorldTransform);
Mover->SetShouldMove(true);
}
else {
UE_LOG(LogTemp, Display, TEXT("Relocking"));
Mover->SetShouldMove(false);
}
}
AActor* UTrigger_Component:: GetAcceptableActor() const {
TArray<AActor*> Actors; //contain the address of the array elememnt
//TSubclassOf< AActor > ClassFilter;
GetOverlappingActors(Actors);
for (AActor* Actor : Actors) {
bool HasAcceptableTag = Actor->ActorHasTag(AcceptableActorTag);//means unlock1 on goggvil
bool HasGrabbed = Actor->ActorHasTag("Grabbed");
if (HasAcceptableTag && !HasGrabbed) {
return Actor;
}
}
return nullptr;
}
void UTrigger_Component::SetMover(UMover* NewMover) {
Mover = NewMover;
}