Hello everyone, I need the assembly animations to be random when it finds the character and this is the way that has occurred to me, but it does not work well sometimes, the animations are mixed sometimes, how could I do it I have been trying for days and almost I am, thank you.
Controller AI
void ADarkShullAIController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
ADarkShullCharacterAI* CharacterAI = Cast<ADarkShullCharacterAI>(GetPawn());
if (DistanceToPlayer > AISinghtRadius) {
bIsPlayerDeteted = false;
}
if (CharacterAI->NextWaypoints != nullptr && bIsPlayerDeteted == false)
{
MoveToActor(CharacterAI->NextWaypoints, 5.f);
}
else if (bIsPlayerDeteted == true)
{
ADarkShullCharacter* Player = Cast<ADarkShullCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
MoveToActor(Player, 50.f);
CharacterAI->MontageIndex = (1 * 400 ) + (FMath::Rand() % ((8 * 400) - (1 * 400) + (1 * 400)));
//UE_LOG(LogTemp, Warning, TEXT(" %d"), CharacterAI->MontageIndex);
CharacterAI->AttackCharacterAI(DeltaTime);
}
}
Character AI
void ADarkShullCharacterAI::AttackCharacterAI(float DeltaTime)
{
GetWorld()->GetTimerManager().SetTimerForNextTick(this, &ADarkShullCharacterAI::AttackAI);
}
void ADarkShullCharacterAI::AttackAI()
{
switch (MontageIndex)
{
case (1 * 400):
AttackAISlice1();
break;
case (2 * 400):
AttackAISlice2();
break;
case (3 * 400):
AttackAISlice3();
break;
case (4 * 400):
AttackAISlice4();
break;
case (5 * 400):
AttackAICombo1();
break;
case (6 * 400):
AttackAICombo2();
break;
case (7 * 400):
AttackAICombo3();
break;
case (8 * 400):
PlayAnimMontage(BallMagicAnim, 1.0f, FName("Start_1"));
BallMagicAudioComponent->SetPitchMultiplier(0.5f);
BallMagicAudioComponent->Play(0.f);
default:
break;
}
}