Door Open Prematurely

for lecture 4.108: Collision Volumes, I found that my doors open when I press play. My Actor is not on the pressure plate area.

I checked the course code, and so far I cannot see where the issue is. I even reverted my InterpTo back to Lerp with the same results.

Most likely problem? Some misplaced letter.

My code:

.CPP

#include "OpenDoor.h"
#include "GameFramework/ACtor.h"
#include "Math/UnrealMathUtility.h"

UOpenDoor::UOpenDoor()
{
	PrimaryComponentTick.bCanEverTick = true;

}


void UOpenDoor::BeginPlay()
{
	Super::BeginPlay();
	
	InitialYaw = GetOwner()->GetActorRotation().Yaw;
	CurrentYaw = InitialYaw;	
	TargetYaw += InitialYaw;

}


void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	
	if (PressurePlate->IsOverlappingActor(ActorThatOpens))
	{
		OpenDoor(DeltaTime);
	}
}

void UOpenDoor::OpenDoor(float DeltaTime)
{
	
	CurrentYaw =FMath::FInterpTo(CurrentYaw, TargetYaw, DeltaTime, 2);

	FRotator DoorRotation = GetOwner()->GetActorRotation();
	DoorRotation.Yaw = CurrentYaw;
	
	GetOwner()->SetActorRotation(DoorRotation);// a place to call up current rotation location and set it

}

.H

// CopyRight MJJH 2021

#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:	
	
	UOpenDoor();

	
protected:
	
	virtual void BeginPlay() override;

public:	
	
	virtual void TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override;
	void OpenDoor(float DeltaTime); 


private:

	float InitialYaw;
	float CurrentYaw;

	UPROPERTY(EditAnywhere)
	float TargetYaw = 90.f;

	UPROPERTY(EditAnywhere)
	ATriggerVolume* PressurePlate;

	UPROPERTY(EditAnywhere)
	AActor* ActorThatOpens;

};

EDIT:
Credit will go to DanM for his prompt, the fix is found below his post.

That’s a bit strange. Would you mind adding logs here?

if (PressurePlate->IsOverlappingActor(ActorThatOpens))
{
    UE_LOG(LogTemp, Warning, TEXT("Opening door"))
    OpenDoor(DeltaTime);
}

As I was about to follow your instructions your message reminded me of something: Did I refresh the code? No.

When I refreshed it everything started working.

Thanks for your help.

Where do I stick the solution? Yours indirectly solved it, mine states what the problem was.

Click the 3 dots next to Reply and you should see

image

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms