I am trying to create a MoveForward input which is coded in C++. Here is my code. It gives the error Error: no matching member for function call to ‘BindAxis’ for InputComponent->BindAxis(“MoveForward”, IE_Pressed, this, &AMainCharacter::movePlayerForward);
Header file:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GameFramework/Character.h"
#include "MainCharacter.generated.h"
UCLASS()
class TESTPROJ_API AMainCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AMainCharacter();
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
virtual void movePlayerForward();
FVector CurrentVelocity;
};
CPP file:
// Fill out your copyright notice in the Description page of Project Settings.
#include "TestProj.h"
#include "MainCharacter.h"
// Sets default values
AMainCharacter::AMainCharacter()
{
// 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;
}
// Called when the game starts or when spawned
void AMainCharacter::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMainCharacter::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// Called to bind functionality to input
void AMainCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
check(InputComponent);
InputComponent->BindAxis("MoveForward", IE_Pressed, this, &AMainCharacter::movePlayerForward);
}
void AMainCharacter::movePlayerForward(){
CurrentVelocity.X = FMath::Clamp(1.0f, -1.0f, 1.0f) * 100.0f;
}
I have also set a Bind Axis in the project settings called MoveForward with the key P. Here is an image of the BindAxis setting.