# I'm trying to create a punch animation for my study project, but it's not working

**URL:** <https://forums.unrealengine.com/t/im-trying-to-create-a-punch-animation-for-my-study-project-but-its-not-working/1861894>\
**Category:** International\
**Tags:** c-c, c-class-wizard, c-and-bluepri, c-custommeshcomponen, c-and-blueprint, c-error, c-class, c-custom-shape, c-programming, c-cone-shape, unreal-engine, CPP, question\
**Created:** [May 18, 2024, 1:28pm UTC](https://forums.unrealengine.com/t/im-trying-to-create-a-punch-animation-for-my-study-project-but-its-not-working/1861894 "2024-05-18T13:28:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AngeloBoni15](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@AngeloBoni15](https://forums.unrealengine.com/u/AngeloBoni15)\
**Post date:** [May 18, 2024, 1:28pm UTC](https://forums.unrealengine.com/t/im-trying-to-create-a-punch-animation-for-my-study-project-but-its-not-working/1861894/1 "2024-05-18T13:28:58Z")

</div>

I’m trying to create a punch animation in a study project of mine, but it’s not running, I wrote the code and I think it’s correct, everything is assigned and when I add the logs they come out correctly, but the animation doesn’t run, which could it be?  
Sorry for the words in portuguese, it’s because i’m form Brazil

```auto
// Fill out your copyright notice in the Description page of Project Settings.

#include "Personagem.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "Animation/AnimMontage.h"
#include "Animation/AnimMontage.h"
#include "Kismet/KismetSystemLibrary.h"

// Sets default values
APersonagem::APersonagem()
{
 	// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;
	Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
	SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm"));

	SpringArm->SetupAttachment(GetRootComponent());
	SpringArm->TargetArmLength = 400.f;

	Camera->SetupAttachment(SpringArm);
//VelAndando == SpeedWalking and VelCorrendo == SpeedRunning
	VelAndando = 600.f;
	VelCorrendo = 1200.f;
}

// Called when the game starts or when spawned
void APersonagem::BeginPlay()
{
	Super::BeginPlay();

	
}

// Called every frame
void APersonagem::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void APersonagem::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
	Super::SetupPlayerInputComponent(PlayerInputComponent);

	PlayerInputComponent->BindAxis(FName("FrenteTras"), this, &APersonagem::Moverfrentetras);
	PlayerInputComponent->BindAxis(FName("MoverLados"), this, &APersonagem::Moverlados);
//MoverFrenteTras == MoveFrontandBackward and MoverLados == MoveSides

	PlayerInputComponent->BindAxis(FName("MoverHorizontal"), this, &APersonagem::MoverHorizontal);
	PlayerInputComponent->BindAxis(FName("MoverVertical"), this, &APersonagem::MoverVertical);
//MoverHorizontal == MoveHorizontally and MoverVertical == MoveVertically

	PlayerInputComponent->BindAction(FName("Correr"),IE_Pressed, this, &APersonagem::Corrida);
	PlayerInputComponent->BindAction(FName("Correr"), IE_Released, this, &APersonagem::PararCorrida);
//Correr == Run

	PlayerInputComponent->BindAction(FName("Pular"), IE_Pressed, this, &APersonagem::Jump);
	PlayerInputComponent->BindAction(FName("Pular"), IE_Released, this, &APersonagem::StopJumping);
//Pular == Jump

	PlayerInputComponent->BindAction(FName("Soco"), IE_Released, this, &APersonagem::IA_Attack);
//Soco == Punch

}

void APersonagem::Moverfrentetras(float Value)
{
	const FRotator ControlRotation = GetControlRotation();
	const FRotator YawRotation(0.f, ControlRotation.Yaw, 0.f);

	const FVector Direcao = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
//Direcao == Direction
	AddMovementInput(Direcao, Value);
}

void APersonagem::Moverlados(float Value)
{
	const FRotator ControlRotation = GetControlRotation();
	const FRotator YawRotation(0.f, ControlRotation.Yaw, 0.f);

	const FVector Direcao = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
//Direcao == Direction
	AddMovementInput(Direcao, Value);

}

void APersonagem::MoverHorizontal(float Value)
{

	AddControllerYawInput(Value);

}

void APersonagem::MoverVertical(float Value)
{
	AddControllerPitchInput(Value);
}

void APersonagem::Corrida()
{

	GetCharacterMovement()->MaxWalkSpeed = VelCorrendo;
//VelAndando == SpeedRunning
}

void APersonagem::PararCorrida()
{
	GetCharacterMovement()->MaxWalkSpeed = VelAndando;
//VelAndando == SpeedWalking
}

void APersonagem::IA_Attack()
{
	if (PunchAnimation)
	{

		UAnimInstance* AnimInstance = GetMesh()->GetAnimInstance();

		if (AnimInstance)
		{
			AnimInstance->Montage_Play(PunchAnimation, 1.0f);
		}
	}
}

```

```auto
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Personagem.generated.h"
class UCameraComponent;
class USpringArmComponent;
class UAnimMontage;

UCLASS()
class LUTA_API APersonagem : public ACharacter
{
	GENERATED_BODY()

public:

	APersonagem();
	virtual void Tick(float DeltaTime) override;
	virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
//MoveFrontandBack
	void Moverfrentetras(float Value);
//MoveSide(Keyboard A and D)
	void Moverlados(float Value);
//Move the mouse in horizontal
	void MoverHorizontal(float Value);
//Move the mouse in vertical
	void MoverVertical(float Value);
//void Running
	void Corrida();
//void StopRunning
	void PararCorrida();
	void IA_Attack();

protected:
	virtual void BeginPlay() override;

private:
	UPROPERTY(EditAnywhere)
	UCameraComponent* Camera;
	UPROPERTY(EditAnywhere)
	USpringArmComponent* SpringArm;
	UPROPERTY(EditAnywhere)
	UAnimMontage* PunchAnimation;

	float VelAndando;
//float speedWalking 
	float VelCorrendo;
//float speedRunning
	

};

```

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/c/28c95c30d8122ab35d5d33bc2fd577ee95946e0a.jpeg)  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/c/4/9c46ae69b591d9d93dc2258126f3863442d07335.png)
