I’m following the fps tutorial from the unreal documentation, and have gotten to the section which involves action mappings, and despite putting jump under action mappings and assigning it to spacebar as per the tutorial, i still can’t get the jump functionality to work when press the spacebar. as for the code, at this point i’ve pretty much written word for word, so have no idea what is causing the problem.
my character header file:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "FPSCharacter.generated.h"
UCLASS()
class BASICFPS_API AFPSCharacter : public ACharacter
{
GENERATED_BODY()
public:
// Sets default values for this character's properties
AFPSCharacter();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
//functions to handle forward and backward movement.
UFUNCTION()
void MoveForward(float value);
UFUNCTION()
void MoveRight(float value);
//functions to handle jumping.
UFUNCTION()
void StartJump();
UFUNCTION()
void StopJump();
};
My cpp file:
// Fill out your copyright notice in the Description page of Project Settings.
#include "FPSCharacter.h"
#include "Engine.h"
// Sets default values
AFPSCharacter::AFPSCharacter()
{
// 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 AFPSCharacter::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Blue, TEXT("This character is currently in use."));
}
}
// Called every frame
void AFPSCharacter::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AFPSCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
//create the bind axis fo the move forward and move right Bindings
PlayerInputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
PlayerInputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
//sets the bidnings for looking up.
PlayerInputComponent->BindAxis("Turn", this, &AFPSCharacter::AddControllerYawInput);
PlayerInputComponent->BindAxis("LookUp", this, &AFPSCharacter::AddControllerPitchInput);
//Jump Bindings.
PlayerInputComponent->BindAction("Jump", IE_Released, this, &AFPSCharacter::StartJump);
PlayerInputComponent->BindAction("Jump",IE_Released, this, &AFPSCharacter::StopJump);
}
void AFPSCharacter::MoveForward(float value)
{
//find out which ay is forward and record the player's request to moe that way.
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, value);
}
void AFPSCharacter::MoveRight(float value)
{
//find out which ay is forward and record the player's request to moe that way.
FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
AddMovementInput(Direction, value);
}
void AFPSCharacter::StartJump()
{
bPressedJump = true;
}
void AFPSCharacter::StopJump()
{
bPressedJump = false;
}
part of the tutorial i’m following:
https://docs.unrealengine.com/latest/INT/Programming/Tutorials/FirstPersonShooter/2/5/index.html