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.