Created
February 21, 2019 17:52
-
-
Save Dok11/010e21ad703e89b38dcc80c380bfc6c6 to your computer and use it in GitHub Desktop.
UE4 APawn Bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright Oleg Postoev | |
#include "OpenDoor.h" | |
#include "GameFramework/Actor.h" | |
// 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 | |
// off to improve performance if you don't need them. | |
PrimaryComponentTick.bCanEverTick = true; | |
// ... | |
} | |
// Called when the game starts | |
void UOpenDoor::BeginPlay() | |
{ | |
Super::BeginPlay(); | |
ActorThatOpens = GetWorld()->GetFirstPlayerController()->GetPawn(); | |
} | |
void UOpenDoor::OpenDoor() | |
{ | |
// Find the own actor | |
AActor* Owner = GetOwner(); | |
// Create a rotator | |
FRotator NewRotation = FRotator(0.f, -60.0f, 0.f); | |
// Set the door rotation | |
Owner->SetActorRotation(NewRotation); | |
} | |
// Called every frame | |
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) | |
{ | |
Super::TickComponent(DeltaTime, TickType, ThisTickFunction); | |
// Poll the trigger volume | |
if (PressurePlate != nullptr && PressurePlate->IsOverlappingActor(ActorThatOpens)) | |
{ | |
OpenDoor(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright Oleg Postoev | |
#pragma once | |
#include "CoreMinimal.h" | |
#include "Components/ActorComponent.h" | |
#include "Engine/TriggerVolume.h" | |
#include "OpenDoor.generated.h" | |
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) | |
class BUILDINGESCAPE_API UOpenDoor : public UActorComponent | |
{ | |
GENERATED_BODY() | |
public: | |
// Sets default values for this component's properties | |
UOpenDoor(); | |
protected: | |
// Called when the game starts | |
virtual void BeginPlay() override; | |
void OpenDoor(); | |
public: | |
// Called every frame | |
virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; | |
private: | |
UPROPERTY(VisibleAnywhere) | |
float OpenAngle = 90.0f; | |
UPROPERTY(EditAnywhere) | |
ATriggerVolume* PressurePlate; | |
class APawn* ActorThatOpens; // Remeber pawn actor | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment