I need help with constantly rotating an Actor with c++

So i try to create a collectable that increases the movement speed of the character. The Actor that i created for that collectable is supposed to rotate, so its prettier.

// Called every frame
void APickup::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

	FRotator Pickup_Current_Rotation = GetActorRotation();
	GEngine->AddOnScreenDebugMessage(-10, 0.5f, FColor::Green, FString::Printf(TEXT("Z %f ; X %f ; Y %f"), Pickup_Current_Rotation.Yaw, Pickup_Current_Rotation.Roll, Pickup_Current_Rotation.Pitch));
	
	FRotator Pickup_Rotation = Pickup_Base_Rotation + (Rotation_Ratio * Pickup_Rotator);
	
	
	if (Pickup_Rotation == Pickup_Base_Rotation)
	{
		Pickup_Rotator += FRotator(90.0f, 90.0f, 90.0f);
		Rotation_Ratio += 1;
	}

	if (Pickup_Current_Rotation == Pickup_Rotation)
	{
		GEngine->AddOnScreenDebugMessage(-1, 3.0f, FColor::Blue, TEXT("Success"));
		Rotation_Ratio += 1;
	}

	if (GetActorRotation() == FRotator(360.0f, 360.0f, 360.0f))
	{
		SetActorRotation(FRotator(0.0f, 0.0f, 0.0f));
	}

	SetActorRotation(FMath::RInterpConstantTo(Pickup_Current_Rotation, Pickup_Rotation, DeltaTime, 50.0f));
	Pickup_Update_Rotation = GetActorRotation();
}

I tried multiple things, so i know that the issue is that, “if (Pickup_Current_Rotation == Pickup_Rotation)” isnt matching the requierments at any point. But i dont understand why it is like that. I tried for multiple hours and im just tired at this point. Im begging for help.

oh, and fyi it stops rotating at FRotator(90.0f, 90.0f, 90.0f).

Thanks in advance

Don’t think this will ever be true since the rotation goes from -180.0 to 180.0.

When comparint floats I always go for >= / <= and only use == when working with clamped values. Still can’t tell for sure why it is never true since you have variables that are declared elseware.

Could you share a visual reference of what you are trying to achieve? I can’t get a clear idea just by looking at the c++. :sweat_smile:

1 Like