Download

Getting controller to move character and camera

G’day

I’m following a tutorial to get character to walk around in third person. I’ve added a camera component to the Avatar I made. The last step I need to take it so move the camera around and make the character walk using WASD.

I think I’ve done what the book says but my character can only look left and right and it doesn’t move at all. I’ve done the axis binding and setup all the functions but there’s still no luck :(. I recompiled just to be sure but I still get the same result.

My .cpp


// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "GoldenEgg.h"
#include "Avatar.h"




void AAvatar::SetupPlayerInputComponent(class UInputComponent *InputComponent)
{
	check(InputComponent);

	/*This member function looks up the Forward and Strafe axis bindings that we just
	created in Unreal Editor and connects them to the member functions inside the this
	class.*/
	InputComponent->BindAxis("Forward", this, &AAvatar::MoveForward);
	InputComponent->BindAxis("Starfe", this, &AAvatar::MoveRight);
	InputComponent->BindAxis("Forward", this, &AAvatar::MoveBack);
	InputComponent->BindAxis("Starfe", this, &AAvatar::MoveLeft);
	InputComponent->BindAxis("Yaw", this, &AAvatar::Yaw);
	InputComponent->BindAxis("Pitch", this, &AAvatar::Pitch);
	//


}

void AAvatar::MoveForward(float amount)
{
	//Don't enter the body of this function if Controller is not set up yet, or if the amount to move is equal to 0
	if (Controller && amount)
	{
		FVector fwd = GetActorForwardVector();
		//we call Add movement input to actually move the player by amount in the fwd direction
		AddMovementInput(fwd, amount);
	}
}

void AAvatar::MoveRight(float amount)
{
	if (Controller && amount)
	{
		FVector right = GetActorRightVector();
		AddMovementInput(right, amount);
	}
}

void AAvatar::MoveLeft(float amount)
{
	if (Controller && amount)
	{
		FVector left = -GetActorRightVector();
		AddMovementInput(left, amount);
	}
}
void AAvatar::MoveBack(float amount)
{
	if (Controller && amount)
	{
		FVector back = -GetActorForwardVector();
		AddMovementInput(back, amount);
	}
}

void AAvatar::Yaw(float amount)
{
	AddControllerYawInput(200.f * amount * GetWorld() ->GetDeltaSeconds());
}
void AAvatar::Pitch(float amount)
{
	AddControllerPitchInput(200.f * amount * GetWorld() ->GetDeltaSeconds());
}

My header file


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

#pragma once

#include "GameFramework/Character.h"
#include "Avatar.generated.h"

/**
 * 
 */
UCLASS()
class GOLDENEGG_API AAvatar : public ACharacter
{
	GENERATED_BODY()
	/*The UCLASS() macro basically makes your C++ code class available in the UE4
	editor. The GENERATED_UCLASS_BODY() macro copies and pastes code that UE4
	needs to make your class function properly as a UE4 class.*/

	//Member function declaration
	//They will be used to move our character
	void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
	void MoveForward(float amount);    //move forward function
	void MoveRight(float amount);	   //move right function
	void MoveBack(float amount);    //move Back function
	void MoveLeft(float amount);	   //move Left function
	void Yaw(float amount);            //Yaw 
	void Pitch(float amount);		   //Pitch

	
	
	
};


Is there something I missed? I’m very new to programming.

Hello you should check this tutorial https://forums.unrealengine.com/showthread.php?64833-Announcing-Section-1-for-Survival-Game.