-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyTriggerBox.cpp
48 lines (38 loc) · 1.14 KB
/
MyTriggerBox.cpp
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
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyTriggerBox.h"
AMyTriggerBox::AMyTriggerBox()
{
OnActorBeginOverlap.AddDynamic(this, &AMyTriggerBox::EnterTeleporter);
OnActorEndOverlap.AddDynamic(this, &AMyTriggerBox::ExitTeleporter);
Teleport = false;
}
void AMyTriggerBox::BeginPlay() {
Super::BeginPlay();
}
void AMyTriggerBox::EnterTeleporter(AActor* overlappedActor, AActor* otherActor)
{
if (otherActor && otherActor != this)
{
if (OtherTeleport)
{
ATeleporterSystemCharacter* Character = Cast<ATeleporterSystemCharacter>(otherActor);
if (Character && !OtherTeleport->Teleport)
{
Teleport = true;
Character->SetActorLocation(OtherTeleport->GetActorLocation());
Character->GetController()->SetControlRotation(Character->GetActorRotation());
Character->SetActorLocation(OtherTeleport->GetActorLocation());
}
}
}
}
void AMyTriggerBox::ExitTeleporter(AActor* overlappedActor, AActor* otherActor)
{
if (otherActor && otherActor != this)
{
if (OtherTeleport && !Teleport)
{
OtherTeleport->Teleport = false;
}
}
}