CryptRaider with Rotator to open doors

As of now, I prefer to continue the course instead of spending time on the CryptRaider level. However, I still wanted to share my door rotation implementation in the hope of some feedback. If there is a much better or simpler solution, please let me know. :wink:

Apart from that, I decided not to disable physics when attaching the triggering actor and to remove the directional / sky lighting due to the tedious light bleed workaround.

Here are the code and some screenshots showing the cell door, which works analogously to the other doors:



RotatorCustom.cpp

#include "RotatorCustom.h"
#include "Math/UnrealMathUtility.h"

URotatorCustom::URotatorCustom()
{
	PrimaryComponentTick.bCanEverTick = true;
}

void URotatorCustom::BeginPlay()
{
	Super::BeginPlay();
	if(!RotatingComponent)
	{
		return;
	}
	StartRotation = RotatingComponent->GetRelativeRotation();
}

void URotatorCustom::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
	if(!RotatingComponent)
	{
		return;
	}
	FRotator CurrentRotation = RotatingComponent->GetRelativeRotation();
	FRotator TargetRotation = StartRotation;
	float InterpSpeed = RotationOffset.Euler().Length() / RotationTime;
	if(ShouldRotate)
	{
		TargetRotation = StartRotation + RotationOffset;
	}
	FRotator NewRotation = FMath::RInterpConstantTo(CurrentRotation, TargetRotation, DeltaTime, InterpSpeed);
	RotatingComponent->SetRelativeRotation(NewRotation);
}

void URotatorCustom::SetShouldRotate(bool NewShouldRotate)
{
	ShouldRotate = NewShouldRotate;
}

void URotatorCustom::SetRotatingComponent(UStaticMeshComponent* NewRotatingComponent)
{
	RotatingComponent = NewRotatingComponent;
	if(!RotatingComponent)
	{
		UE_LOG(LogTemp, Error, TEXT("%s: RotatingComponent nullptr"), *GetName());
		return;
	}
	StartRotation = RotatingComponent->GetRelativeRotation();
}

Thanks for taking a look! :smiley:

5 Likes

Privacy & Terms