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);
RotateDoor(0.3f);
}
void UOpenDoor::RotateDoor(float RotationSpeed){
FRotator CurrentRotation = GetOwner()->GetActorRotation();
//Don't call GetOwner() is the constructor.
if(CurrentRotation.Yaw < 89)
{
CurrentRotation.Yaw += RotationSpeed;
}
else
{
CurrentRotation.Yaw = 90;
}
GetOwner()->SetActorRotation(CurrentRotation);
}
.h file:
UCLASS( ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) )
class BUILDING_ESCAPE_API UOpenDoor : public UActorComponent
{
GENERATED_BODY()
public:
// Sets default values for this component's properties
UOpenDoor();
void RotateDoor(float RotationSpeed);
And a video of the end result: https://youtu.be/RYbzptTnAbI