First Person Shooter (Tutorial) - WASD problems

Great tutorial, but I am unable to receive/detect player WASD input after going through all the steps to the letter. Any help would be appreciated!

Details

  1. created the all classes and editor settings as specified (all input mappings have been set up correctly as well)

  2. debug print will show up for SetupPlayerInputComponent

  3. debug prints will not show up for MoveForward/Moveright when keys are pressed, but the functions are definitely getting called every frame



void AFPSCharacter::MoveRight(float Value)
{

	//this will show up every frame when the game is run
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("MoveRight function called"));


	if ((Controller != NULL) && (Value != 0.0f))
	{
		//this never gets called when keyboard is pressed for some reason
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("MoveRight Input received"));
	
		//find out which way is right
		const FRotator Rotation = Controller->GetControlRotation();
		const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
		//Add movement in that direction
		AddMovementInput(Direction, Value);

	}

}


Worth noting that the tutorial section after WASD (mouse input) works fine (able to detect and use the mouse input)

Hmm everything looks fine to me. Try this, I currently am using it in my game and it works.


	if ((Controller != NULL) && (Value != 0.0f))
	{
		FRotator Rotation = Controller->GetControlRotation();
		const FVector MoveDirection = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
		AddMovementInput(MoveDirection, Value);
	}

Thanks for the reply. The problem isn’t that particular code block, it’s that the block of code just never gets run. Anything after “if ((Controller != NULL) && (Value != 0.0f))” never gets hit at all, even though I am mashing on the wasd keys and all my bindings are correct in project settings (exactly like the tutorial screen below)

Here’s where the MoveRight and MoveForward functions are declared (in FPScharacter.h) in case it provides any clues. The functions get called every frame, I’m just not receiving wasd keyboard input (space bar works fine for jump though…strange stuff)



UCLASS() //this macro makes Unreal aware of your class, allowing it to perform optimizations, etc
class AFPSCharacter : public ACharacter		//Class Declaration
{

	GENERATED_UCLASS_BODY()				//macro that supplies automatic definitions

	//Declare a first person camera
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
		TSubobjectPtr<UCameraComponent> FirstPersonCameraComponent;

	//Declare a first person mesh visible only to player
	UPROPERTY(VisibleDefaultsOnly, Category = Mesh)
		TSubobjectPtr<USkeletalMeshComponent> FirstPersonMesh;

	virtual void BeginPlay() OVERRIDE;	//declare the func and that it will override the BeginPlay() in the parent class, AActor



	protected:
		virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) OVERRIDE;

	UFUNCTION()						//UFUNCTION makes engine aware function below it
	void MoveForward(float Val);	//handles moving forward/backward
	UFUNCTION()
	void MoveRight(float Val);		//handles strafing
	UFUNCTION()
	void OnStartJump();				
	UFUNCTION()
	void OnStopJump();


};


I too am experiencing this problem, although slightly different. Right now I am up to the WASD part of the tutorial, and have not moved on. My bindings in the editor resemble that of the screenshot clu provided.

Similar to what clu posted, I placed on screen debug messages in the move forward, move right, and the SetupPlayerInputComponent functions (methods) and none are displaying.

The “Hello World” (FPSGameMode.cpp), and “We are using FPSCharacter!” (FPSCharacter.cpp) are both displaying correctly per the tutorial.

Sorry to double post, but maybe this will help chu.

In the template source code from GitHub the file “TP_FirstPersonCharacter.cpp” functions (methods) do not have a check for Controller != Null


void ATP_FirstPersonCharacter::MoveForward(float Value)
{
	if (Value != 0.0f)
	{
		// find out which way is forward
		const FRotator Rotation = GetControlRotation();
		FRotator YawRotation(0, Rotation.Yaw, 0);

		// Get forward vector
		const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);

		// add movement in that direction
		AddMovementInput(Direction, Value);
	}
}

void ATP_FirstPersonCharacter::MoveRight(float Value)
{
	if (Value != 0.0f)
	{
		// find out which way is right
		const FRotator Rotation = GetControlRotation();
		const FRotator YawRotation(0, Rotation.Yaw, 0);

		// Get right vector
		const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);

		// add movement in that direction
		AddMovementInput(Direction, Value);
	}
}

I suppose something is wrong with your BindAxis commands. Could you post them?


InputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
InputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);

Check the spelling of your binding names. If they’re wrong, the functions won’t get called.

Mine are:


void AFPSCharacter::SetupPlayerInputComponent(UInputComponent* InputComponent)
{
	
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("SetupPlayerInputComponent function called"));
	// set up gameplay key bindings
	InputComponent->BindAxis("MoveForward", this, &AFPSCharacter::MoveForward);
	InputComponent->BindAxis("MoveRight", this, &AFPSCharacter::MoveRight);
}

Although as mentioned above I am not even getting the on screen message that the function is being called. All code in my project has been copy and pasted from the wiki and compiles without errors. I have verified that the inputs are named “MoveForward” & “MoveRight” in the editor - project - input section also.

Resolved. Stupid typo, but not in the code. Make sure in the input settings under Axis mappings (under edit->project settings) that there are no spaces in “MoveForward” and “MoveRight”

EDIT: Thanks Daerst…just saw your post =)

ra_ar, do you have OVERRIDE set on the SetupPlayerInputComponent declaration in FPSCharacter.h? Might be why it isn’t getting called at all.



	protected:
		virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) OVERRIDE;


The rest of my FPSCharacter.h is above in this thread, right underneath the screenshot I posted of the binding settings, in case it’s any help (my SetupPlayerInputComponent func is getting called no problem)

I was thrown off here too. Make sure you click in the 3d viewport after clicking play. What I mean to say is; Compile your code, open your project, click play, then click in the 3d window where you see your map. I realized that the input was not working until your click in the viewport.

chu, yes it was set. I copied it straight from the wiki article. I’m going to continue along in the tutorial. Maybe there is something that has to occur later in regards to the camera to get this working?

Thank you nickgamb, I have tried that though and it is still not working.

Ok, so I committed a dumb. Last night when I was compiling in VSE I had it using the “Development Editor”. Today when I continued the default option was “DebugGameEditor”.

Everything is working now that I selected the correct “Solutions Configurations” today. :slight_smile:

Haha I always hate that… 1 thing goes wrong and the whole thing doesn’t work! :stuck_out_tongue: