// Fill out your copyright notice in the Description page of Project Settings.
#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();
// Intializing the TargetYaw according to it's Initial Location
TargetYaw = GetOwner()->GetActorRotation().Yaw + 90.f;
}
// Called every frame
void UOpenDoor::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
float CurrentYaw = GetOwner()->GetActorRotation().Yaw;
FRotator Rotation (0.f,FMath::FInterpTo(CurrentYaw,TargetYaw,DeltaTime,2),0.f);
GetOwner()->SetActorRotation(Rotation);
UE_LOG(LogTemp, Warning , TEXT("Value of Yaw is : %s "),*GetOwner()->GetActorRotation().ToString());
// ...
}
So the Header file is as it is shown in lecture but I didn’t initialize it. What I did here, is I initialized the TargetYaw in BeginPlay() but adding 90 from it’s initial value. And code is working perfectly.
One More Thing, When I used “FInterpConstantTo” instead of “FInterpTo”, the second door ( The one which is not attached with wall in Video) kept rotating. may be that is just with me or some Unreal Glitch.