Today I wanted to adapt my code so the player cannot move again until their position is reset, also I wanted to add alternating arms so the enemy will punch with the correct side when they move.
Player C++ file
void ACompetitionCharacter::Dodge(const FInputActionValue& Value)
...
if (Controller && (DirectionValue != 0.f) && CanMove == true)
...
CanMove = false;
...
void ACompetitionCharacter::Punch(const FInputActionValue& Value)
if (CanMove == true)
...
CanMove = false
...
void ACompetitionCharacter::Retreat()
...
CanMove = true;
Here, I added the variable “CanMove” to dictate the players control over the character. Now any movement will set this value to false and stop the player from moving until the “Retreat” function is called and it is set to true.
Enemy C++ file
void ACompetitionEnemy::SpawnPunch()
if (ACompetitionEnemy::GetActorLocation().Y > StartLocal.Y)
{
...
LeftArmBox->SetRelativeTransform(FTransform(FQuat::Identity, FVector(-20, 20, 0), FVector(1.2, -0.1, -0.1)));
}
else if (ACompetitionEnemy::GetActorLocation().Y < StartLocal.Y)
{
...
LeftArmBox->SetRelativeTransform(FTransform(FQuat::Identity, FVector(-20, -20, 0), FVector(1.2, -0.1, -0.1)));
This code sets the initial position of the arm differently depending on which side the enemy moved to.
void ACompetitionEnemy::ThrowPunch()
if (LeftArmBox)
{
//Extends arm
LeftArmBox->SetRelativeTransform(FTransform(FQuat::Identity, FVector(50, LeftArmBox->GetRelativeLocation().Y, 0), FVector(1.2, -0.1, -0.1)));
Now when the arm extends, the new position will use the correct Y coordinate.