open door with pawn

This commit is contained in:
Tyrel Souza 2018-02-19 20:57:42 -05:00
parent 4f8c44b40f
commit 037108763f
3 changed files with 21 additions and 18 deletions

View File

@ -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

View File

@ -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();
}
}

View File

@ -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
@ -33,4 +34,6 @@ private:
UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;
UPROPERTY(EditAnywhere)
AActor* ActorThatOpens;
};