Allow door to open, timing, default pawn, grabber start

This commit is contained in:
Tyrel Souza 2018-02-19 22:05:11 -05:00
parent edb48dba0b
commit 2f67151c4a
10 changed files with 92 additions and 13 deletions

View File

@ -0,0 +1,2 @@

View File

@ -2,7 +2,7 @@
[/Script/EngineSettings.GameMapsSettings]
EditorStartupMap=/Game/NewMap.NewMap
GameDefaultMap=/Game/NewMap.NewMap
GlobalDefaultGameMode=/Script/RoomEscape.RoomEscapeGameModeBase
GlobalDefaultGameMode=/Game/MyRoomEscapeGameModeBase_BP.MyRoomEscapeGameModeBase_BP_C
[/Script/HardwareTargeting.HardwareTargetingSettings]
TargetedHardwareClass=Desktop
@ -51,3 +51,4 @@ AsyncSceneSmoothingFactor=0.990000
InitialAverageFrameRate=0.016667
PhysXTreeRebuildRate=10

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,33 @@
// Tyrel Souza 2018
#include "Grabber.h"
// Sets default values for this component's properties
UGrabber::UGrabber()
{
// 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;
}
// Called when the game starts
void UGrabber::BeginPlay()
{
Super::BeginPlay();
UE_LOG(LogTemp, Warning, TEXT("Grabber beginPlay"));
}
// Called every frame
void UGrabber::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
}

View File

@ -0,0 +1,29 @@
// Tyrel Souza 2018
#pragma once
#include "CoreMinimal.h"
#include "Components/ActorComponent.h"
#include "Grabber.generated.h"
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class ROOMESCAPE_API UGrabber : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UGrabber();
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
};

View File

@ -19,28 +19,37 @@ UOpenDoor::UOpenDoor()
void UOpenDoor::BeginPlay()
{
Super::BeginPlay();
OwningDoor = GetOwner();
ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn();
}
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);
FString Rot = OwningDoor->GetTransform().GetRotation().GetAxisZ().ToString();
OwningDoor->SetActorRotation(FRotator(0.0f, OpenAngle, 0.0f));
}
void UOpenDoor::CloseDoor() {
FString Rot = OwningDoor->GetTransform().GetRotation().GetAxisZ().ToString();
OwningDoor->SetActorRotation(FRotator(0.0f, 0.0f, 0.0f));
}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
float CurSeconds = GetWorld()->GetTimeSeconds();
// poll the TriggerVolume every frame
// if ActorThatOpens is in the volume, open door
if (PressurePlate->IsOverlappingActor(ActorThatOpens)) {
OpenDoor();
LastDoorOpenTime = CurSeconds;
}
//check if time to close door
if (CurSeconds > LastDoorOpenTime + DoorCloseDelay) {
CloseDoor();
}
}

View File

@ -18,21 +18,26 @@ public:
// Sets default values for this component's properties
UOpenDoor();
void OpenDoor();
void CloseDoor();
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
protected:
// Called when the game starts
virtual void BeginPlay() override;
public:
// Called every frame
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
private:
UPROPERTY(VisibleAnywhere)
float OpenAngle = 90.f;
UPROPERTY(EditAnywhere)
float OpenAngle = -90.f;
UPROPERTY(EditAnywhere)
ATriggerVolume* PressurePlate;
UPROPERTY(EditAnywhere)
float DoorCloseDelay = 1.f;
float LastDoorOpenTime;
AActor* ActorThatOpens;
AActor* OwningDoor;
};