Ok!
This’s the Avatar.h class
// 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_UCLASS_BODY()
void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
void MoveForward(float amount);
void MoveRight(float amount);
void MoveLeft(float amount);
void MoveBack(float amount);
void Yaw(float amount);
void Pitch(float amount);
public:
// Sets default values for this character’s properties
AAvatar();
// 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;
};
And this, Avatar.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include “GoldenEgg.h”
#include “Avatar.h”
// Sets default values
AAvatar::AAvatar()
{
// 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 AAvatar::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AAvatar::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// Called to bind functionality to input
void AAvatar::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
Super::SetupPlayerInputComponent(InputComponent);
check(InputComponent);
InputComponent->BindAxis("Forward", this, &AAvatar::MoveForward);
InputComponent->BindAxis("Strafe", this, &AAvatar::MoveRight);
InputComponent->BindAxis("Yaw", this, &AAvatar::Yaw);
InputComponent->BindAxis("Pitch", this, &AAvatar::Pitch);
}
void AAvatar::MoveForward(float amount){
if (Controller && amount){
FVector fwd = GetActorForwardVector();
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());
}