From 037108763feeaf30ba14bfc2a98950545d04a0a9 Mon Sep 17 00:00:00 2001 From: Tyrel Souza Date: Mon, 19 Feb 2018 20:57:42 -0500 Subject: [PATCH] open door with pawn --- RoomEscape/Config/DefaultEngine.ini | 3 +-- RoomEscape/Source/RoomEscape/OpenDoor.cpp | 31 ++++++++++++----------- RoomEscape/Source/RoomEscape/OpenDoor.h | 5 +++- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/RoomEscape/Config/DefaultEngine.ini b/RoomEscape/Config/DefaultEngine.ini index d34d9dc..63c5815 100644 --- a/RoomEscape/Config/DefaultEngine.ini +++ b/RoomEscape/Config/DefaultEngine.ini @@ -2,7 +2,7 @@ [/Script/EngineSettings.GameMapsSettings] EditorStartupMap=/Game/NewMap.NewMap GameDefaultMap=/Game/NewMap.NewMap -GlobalDefaultGameMode="/Script/RoomEscape.RoomEscapeGameMode" +GlobalDefaultGameMode=/Script/RoomEscape.RoomEscapeGameModeBase [/Script/HardwareTargeting.HardwareTargetingSettings] TargetedHardwareClass=Desktop @@ -51,4 +51,3 @@ AsyncSceneSmoothingFactor=0.990000 InitialAverageFrameRate=0.016667 PhysXTreeRebuildRate=10 - diff --git a/RoomEscape/Source/RoomEscape/OpenDoor.cpp b/RoomEscape/Source/RoomEscape/OpenDoor.cpp index d52b75c..f7c115d 100644 --- a/RoomEscape/Source/RoomEscape/OpenDoor.cpp +++ b/RoomEscape/Source/RoomEscape/OpenDoor.cpp @@ -7,11 +7,10 @@ // Sets default values for this component's properties UOpenDoor::UOpenDoor() { - // Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features + // Set this component to be initialized when the game starts, and to be ticked every frame. + // You can turn these features // off to improve performance if you don't need them. PrimaryComponentTick.bCanEverTick = true; - - // ... } @@ -20,26 +19,28 @@ void UOpenDoor::BeginPlay() { Super::BeginPlay(); - AActor* Owner = GetOwner(); - FString ObjectName = Owner->GetName(); - - - FString Rot = Owner->GetTransform().GetRotation().GetAxisZ().ToString(); - UE_LOG(LogTemp, Warning, TEXT("%s is at: %s"), *ObjectName, *Rot); - - - FRotator NewRotation = FRotator(0.0f, -90.0f, 0.0f); - - Owner->SetActorRotation(NewRotation); } +void UOpenDoor::OpenDoor() { + AActor* Owner = GetOwner(); + FString ObjectName = Owner->GetName(); + FString Rot = Owner->GetTransform().GetRotation().GetAxisZ().ToString(); + FRotator NewRotation = FRotator(0.0f, -90.0f, 0.0f); + Owner->SetActorRotation(NewRotation); +} + // Called every frame void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); - // ... + // poll the TriggerVolume every frame + // if ActorThatOpens is in the volume, open door + if (PressurePlate->IsOverlappingActor(ActorThatOpens)) { + OpenDoor(); + } + } diff --git a/RoomEscape/Source/RoomEscape/OpenDoor.h b/RoomEscape/Source/RoomEscape/OpenDoor.h index 149c4f8..e39da16 100644 --- a/RoomEscape/Source/RoomEscape/OpenDoor.h +++ b/RoomEscape/Source/RoomEscape/OpenDoor.h @@ -17,6 +17,7 @@ class ROOMESCAPE_API UOpenDoor : public UActorComponent public: // Sets default values for this component's properties UOpenDoor(); + void OpenDoor(); protected: // Called when the game starts @@ -32,5 +33,7 @@ private: UPROPERTY(EditAnywhere) ATriggerVolume* PressurePlate; - + + UPROPERTY(EditAnywhere) + AActor* ActorThatOpens; };