Hello guys, I’m trying to rotate a revolver handgun cylinder each shot by i had a problem after three 3 shots when roll is near to 180 …
void Weapon::FireWeapon()
{
Super::FireWeapon();
float CurrentRoll = CylinderComp->RelativeRotation.Roll;
if (CurrentAmmo -1 < MaxAmmo / 2)
{
MaxRoll = ((CurrentAmmo * -1) * 60);
}
else
{
//This section works for three first shot
MaxRoll = (MaxAmmo - CurrentAmmo + 1) * 60;
}
GetWorldTimerManager().SetTimer(TimerHandle_CylinderAnim, this, &Weapon::AnimateCylinder, 0.01, true);
}
void Weapon::AnimateCylinder()
{
float CurrentRoll = CylinderComp->RelativeRotation.Roll;
FRotator CurrentRotation = CylinderComp->RelativeRotation;
float TargetRoll = 0;
TargetRoll = FMath::FInterpTo(CurrentRoll, MaxRoll, GetWorld()->GetDeltaSeconds(), 18);
CurrentRotation.Roll = TargetRoll;
CylinderComp->SetRelativeRotation(CurrentRotation.Quaternion());
if (TargetRoll >= MaxRoll)
{
GetWorldTimerManager().ClearTimer(TimerHandle_CylinderAnim);
}
}
The problem is i don’t know how to handle when degree is greater than 180 as UE4 rotation system is a little bit different!
Regards