(100 Rotating An Actor With Code)Learn C++ and make Video Games

Hey All,

This is my first post here but I’ve been following along with the Unreal Engine C++ Developer: Learn C++ and Make Video Games tutorial serious after work hours and have been enjoying it quite a lot. I have some programming experience and love to play around with the code bits we get taught. In the past I could never get my head around parsing a variable in a function and how to use them but tonight I figured it out.

In the specific tutorial we are requested to rotate a door in a test level to 90 degrees in the BeginPlay function. I decided to challenge myself a bit and make it in the TickComponent function so I could “animate” the rotation instead of just starting the scene and having the door at 90 degrees.

When that worked I challenged myself by creating a function that parses the rotation speed as per my code:
.cpp file:

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



void UOpenDoor::RotateDoor(float RotationSpeed){
	FRotator CurrentRotation = GetOwner()->GetActorRotation();
	//Don't call GetOwner() is the constructor.

	if(CurrentRotation.Yaw < 89)
		CurrentRotation.Yaw += RotationSpeed;
		CurrentRotation.Yaw = 90;


.h file:

UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDING_ESCAPE_API UOpenDoor : public UActorComponent

	// Sets default values for this component's properties
	void RotateDoor(float RotationSpeed);

And a video of the end result: https://youtu.be/RYbzptTnAbI

1 Like

Great post and video! :100:

Privacy & Terms