Session 67
[kaeril_buildingescape.git] / Source / BuildingEscape / OpenDoor.cpp
bloba20d695e24558e792d07cd949f2683d3dda432e1
1 // Fill out your copyright notice in the Description page of Project Settings.
3 #include "BuildingEscape.h"
4 #include "OpenDoor.h"
7 // Sets default values for this component's properties
8 UOpenDoor::UOpenDoor()
10 // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
11 // off to improve performance if you don't need them.
12 bWantsBeginPlay = true;
13 PrimaryComponentTick.bCanEverTick = true;
15 // ...
19 // Called when the game starts
20 void UOpenDoor::BeginPlay()
22 Super::BeginPlay();
24 ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
25 Owner = GetOwner();
28 void UOpenDoor::OpenDoor()
30 Owner->SetActorRotation(FRotator(0.0f, OpenAngle, 0.0f));
33 void UOpenDoor::CloseDoor()
35 Owner->SetActorRotation(FRotator(0.0f, 0.0f, 0.0f));
38 // Called every frame
39 void UOpenDoor::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
41 Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
43 // Poll the TriggerVolume
44 // If the ActorThatOpens is in the volume
45 if (PressurePlate->IsOverlappingActor(ActorThatOpens))
47 OpenDoor();
48 LastDoorOpenTime = GetWorld()->GetTimeSeconds();
51 // Check if it's time to close the door
52 if (GetWorld()->GetTimeSeconds() - LastDoorOpenTime > DoorCloseDelay)
54 CloseDoor();