Hi, I am making a simple Pickup actor and on the Tick function I want to rotate it with the FRotator(15, 30, 45) each second. I encountered a strange bug (The rotation around the Pitch axis locks after 90deg). I wan’t to do this via C++ so please don’t answer with blueprints.
Here is the code if it might help:
// Pickup.h
UCLASS()
class APickup : public AActor
{
GENERATED_UCLASS_BODY()
public:
/** The root component of the pickup object */
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Components")
TSubobjectPtr<USceneComponent> SceneComponent;
/** The static mesh of the pickup object */
UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = "Components")
TSubobjectPtr<UStaticMeshComponent> PickupMesh;
/** The rotation rate of the pickup object in degrees/second for each axis of the FRotator */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Rotation")
FRotator RotationRate;
virtual void Tick(float DeltaTime) override;
};
// Pickup.cpp
APickup::APickup(const FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
this->PrimaryActorTick.bCanEverTick = true;
this->SceneComponent = PCIP.CreateDefaultSubobject<USceneComponent>(this, TEXT("SceneComponent"));
this->RootComponent = this->SceneComponent;
this->PickupMesh = PCIP.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("PickupMesh"));
this->PickupMesh->AttachTo(this->RootComponent);
this->RotationRate = FRotator(15.0f, 30.0f, 45.0f);
}
void APickup::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
this->SetActorRotation(this->GetActorRotation() + (this->RotationRate * DeltaTime));
}