Hello and thank you for taking the time to look at my question.
I am working on a class that rotates an actor around the Yaw axis. My goal is to rotate the actor in certain degree increments over a variable amount of time. For now I would like the increments to be 90 degrees, for example: 0, 90, -180, -90 or 0, 90, 180, 270.
First I have a question about why in the Transform section of Details of an object, the Rotation value scales from 0 to 360 but once I am in Play mode and start Rotating things the scale seems to be -180 to 180?
As of right now I am able to continuously rotate my actor, but I’ve run in to issues stopping the rotation at the right float value. I am always off but some value < or > 1. What I am asking for is guidance on how to ensure my rotations stop at whole numbers and how to clamp my rotations between 0 and 360. If I am going about this all wrong, please let me know. I am new to Unreal so I have yet to even scratch the surface of all of the various functions available. If anyone could point me in the right direction that would be greatly appreciated. My alternate approach would be to create some animations for each rotation in the editor, and play each animation based on the current angle of the actor. I am thinking I will run into similar problems though.
I am aware I can accomplish my goal in BP quite easily but I am specifically trying to improve my unreal & c++ abilities.
Thank you once again for your time an consideration.
// Called every frame
void ACameraRotator::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
// if a player hits the input to rotate the camera right
if (bRotateRightToggle == true && bRotateLeftToggle == false)
{
RotateRight(DeltaTime);
}
if (bRotateLeftToggle == true && bRotateRightToggle == false)
{
RotateLeft(DeltaTime);
}
}
void ACameraRotator::RotateRight(float DeltaTime)
{
// conditionals for 0, 90, -180, -90 would go here
if (GetActorRotation().Yaw == 90.f) {
bRotateRightToggle = false;
return;
}
else
{
FQuat QuatRotation = FQuat(FRotator(0.f, RotationSpeed * DeltaTime, 0.f));
AddActorLocalRotation(QuatRotation, false, 0, ETeleportType::None);
}
}
void ACameraRotator::RotateLeft(float DeltaTime)
{
FQuat QuatRotation = FQuat(FRotator(0.f, -RotationSpeed * DeltaTime, 0.f));
AddActorLocalRotation(QuatRotation, false, 0, ETeleportType::None);
}