In this session, I wanted to focus on adding my super punch animation for the perfect dodge ability.
Player CPP file
void ACompetitionCharacter::Dodge()
{
...
if (DodgeWindow == true)
{
UGameplayStatics::SetGlobalTimeDilation(GetWorld(), 0.1f);
CameraTempPos = FVector(0, DirectionValue * 100, 0);
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, TEXT("Spam Click to charge the punch"));
//set a timer for the super punch
State = "PerfectDodge";
GetWorldTimerManager().SetTimer(MovementHandler, this, &ACompetitionCharacter::SuperPunch, 1.0f, false);
//Timer for camera movement GetWorldTimerManager().SetTimer(CameraHandler, 1.0f, false);
...
else
{
GetWorldTimerManager().SetTimer(MovementHandler, this, &ACompetitionCharacter::Retreat, 1.0f, false);
State = "Dodging";
I moved some code from “PerfectDodge” into the dodge function as to improve consistency. Also, I added the code for the camera movement to be executed here and removed it from the default punch. If the player achieves a perfect dodge: they will be prompted to start clicking, time will slow and a timer will be set for when the clicks are checked; along with the camera timer for smooth camera movement. Otherwise, the dodge is carried out normally.
void ACompetitionCharacter::ResetPunch()
{
UGameplayStatics::SetGlobalTimeDilation(GetWorld(), 1.0f);
GetWorldTimerManager().SetTimer(CameraHandler, this, &ACompetitionCharacter::Retreat, 1.0f, false);
“ResetPunch” is now used only for the super punch, resetting time dilation and retreating the character. The “PerfectDodge” function has also been removed as it is unnecessary now.
void ACompetitionCharacter::SuperPunch()
{
...
if (PunchCharge >= 10)
{
State = "SuperPunch";
GetWorldTimerManager().SetTimer(PunchTimerHandle, this, &ACompetitionCharacter::ResetPunch, 1.0f, false);
}
else
{
//reset time speed UGameplayStatics::SetGlobalTimeDilation(GetWorld(), 1.0f);
Retreat();
If the player reaches the correct amount of clicks, the “SuperPunch” animation is played and “ResetPunch” is called after a timer. Otherwise, time dilation is reset and the player returns to their original position.
void ACompetitionCharacter::Tick()
...
if (GetWorld()->GetTimerManager().IsTimerActive(CameraHandler) == true)
{
if (State == "PerfectDodge")
...
else
Camera interpolation is now carried out on “PerfectDodge” and reset when the handler is used again afterwards.
Animation Blueprint
