Finished Door opening mechanic

This commit is contained in:
MH261677 2023-11-21 14:31:33 +00:00
parent 14c1874c53
commit 55e160eb80
6 changed files with 39 additions and 13 deletions

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:162297ec59b7e47b42f34b19c64b0cbca86fcf80168764e5047cc45910cfe7da
size 4366

View File

@ -3,6 +3,10 @@
#include "DoorClass.h" #include "DoorClass.h"
#include "EndlessVendettaCharacter.h"
#include "Components/ArrowComponent.h"
#include "Kismet/GameplayStatics.h"
// Sets default values // Sets default values
ADoorClass::ADoorClass() ADoorClass::ADoorClass()
{ {
@ -16,33 +20,43 @@ void ADoorClass::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
// Attempt to find the player character
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0);
playerInWorld = Cast<AEndlessVendettaCharacter>(PlayerController->GetCharacter());
endlessVendettaChar = Cast<AEndlessVendettaCharacter>(playerInWorld);
for (UActorComponent* actorComp : playerInWorld->GetComponentsByTag(UArrowComponent::StaticClass(), FName("FrontOfDoor")))
{
FrontOfDoor = Cast<UArrowComponent>(actorComp);
break;
}
} }
// Called every frame // Called every frame
void ADoorClass::Tick(float DeltaTime) void ADoorClass::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
} }
void ADoorClass::Interact() void ADoorClass::Interact()
{ {
if (!IsValid(this)) return; if (!IsValid(this)) return;
GLog->Log("Door has been interacted");
bool bIsDoorOpen = false;
if (!bIsDoorOpen) if (!bIsDoorOpen)
{ {
DoorOpeningAnim();
bIsDoorOpen = true; bIsDoorOpen = true;
} }
else else
{ {
DoorCloseAnim();
bIsDoorOpen = false; bIsDoorOpen = false;
} }
} }
void ADoorClass::InteractPrompt() void ADoorClass::InteractPrompt()
{ {
if(bIsDoorOpen) return;
DoorPrompt(); DoorPrompt();
} }

View File

@ -3,6 +3,7 @@
#pragma once #pragma once
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Components/ArrowComponent.h"
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "EndlessVendetta/InteractionInterface.h" #include "EndlessVendetta/InteractionInterface.h"
#include "DoorClass.generated.h" #include "DoorClass.generated.h"
@ -22,6 +23,12 @@ protected:
// Called when the game starts or when spawned // Called when the game starts or when spawned
virtual void BeginPlay() override; virtual void BeginPlay() override;
ACharacter* playerInWorld;
AEndlessVendettaCharacter* endlessVendettaChar;
UArrowComponent* FrontOfDoor;
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
@ -33,4 +40,12 @@ public:
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void DoorPrompt(); void DoorPrompt();
UFUNCTION(BlueprintImplementableEvent)
void DoorOpeningAnim();
UFUNCTION(BlueprintImplementableEvent)
void DoorCloseAnim();
bool bIsDoorOpen = false;
}; };