Skip to content

Instantly share code, notes, and snippets.

@p30virus
Created July 6, 2023 13:43
Show Gist options
  • Select an option

  • Save p30virus/ef155f4052613a7adcfdd5224cf37946 to your computer and use it in GitHub Desktop.

Select an option

Save p30virus/ef155f4052613a7adcfdd5224cf37946 to your computer and use it in GitHub Desktop.
// Fill out your copyright notice in the Description page of Project Settings.
#include "AnotherCamera/Public/RotatingActor.h"
// Sets default values
ARotatingActor::ARotatingActor()
{
PrimaryActorTick.bCanEverTick = true;
//This will create a non "visible" scene component that is the base of your actor
RotationObjectRoot->CreateDefaultSubobject<USceneComponent>(TEXT("RotationObjectRoot"));
if(RotationObjectRoot == nullptr)
{
return;
}
//This will add that that component as the root of your actor
SetRootComponent(RotationObjectRoot);
//THis will create the mesh that you can see on the actor and is going to rotate relative to the root component
RotatingObject->CreateDefaultSubobject<UStaticMeshComponent>(TEXT("RotatingObject"));
if(RotatingObject == nullptr)
{
return;
}
// this will add the component as a "child" of the root component
RotatingObject->SetupAttachement(RotationObjectRoot);
}
// Called when the game starts or when spawned
void ARotatingActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void ARotatingActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if(RotatingObject)
{
RotatingObject->AddRelativeRotation(AddRelativeRotation);
}
}
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "RotatingActor.generated.h"
UCLASS()
class ANOTHERCAMERA_API ARotatingActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
ARotatingActor();
UPROPERTY(BlueprintReadWrite, EditAnywhere)
USceneComponent* RotationObjectRoot;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UStaticMeshComponent* RotatingObject;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
UStaticMeshComponent* RotatingObject;
UPROPERTY(BlueprintReadWrite, EditAnywhere)
FRotator AddRelativeRotation;
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment