So I’m attempting a simple reload animation through c++ by rotating a scene component that is parented to my gun mesh. The idea is when the user presses the fire button that will trigger a bool to run in the Tick function but I’m not sure how I would loop the logic to have the rotation stop on a full 360 and turn the bool to false.
void ANordic_Cowboy_FPSCharacter::Tick(float DeltaTime) {
Super::Tick(DeltaTime);
if (reloadRotate)
{
FRotator rotationToAdd = FRotator(5.f, 0.f, 0.f);
ShotgunParent->AddLocalRotation(rotationToAdd);
}
}
I’ve looked around for a lot but I’m still not necessarily sure how I would create the control logic for looping or just any alternatives. Any input would be appreciated, thank you!
I sorta think I know what you’re after, but if I’m completely off, feel free to ignore the following.
So, from the looks of your code sample, you’re adding 5 to just the pitch on each tick. The simplest way to achieve what you’re after with your given code would be to store a float representing how much you’ve rotated the pitch by since last tick. Initially, set it to 0. Then, when reloadRotate is true, add 5 to each time you add 5 to the ShotgunParent’s pitch. Once it’s >= 360, reset. So, assuming you have a float currentRotate = 0 to start with:
if (reloadRotate)
{
FRotator rotationToAdd = FRotator(5.f, 0.f, 0.f);
ShotgunParent->AddLocatRotation(rotationToAdd);
currentRotate += 5.0f;
if (currentRotate >= 360.0f)
{
currentRotate = 0.0f;
reloadRotate = false;
}
}
Is this what you’re after?
Thats exactly what I was after thanks so much the help!