Hey eveyone! I am pretty new to C++ and UE4 and I am trying to make a simple breakout game. Right now I have the paddle moving left and right but I am trying to figure out how to expose a variable to reduce the speed of the paddle.
Here is my code:
Paddle.h
#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "Paddle.generated.h"
UCLASS()
class BREAKOUT_API APaddle : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
APaddle();
UPROPERTY(EditAnywhere)
UStaticMeshComponent* PaddleMesh;
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;
void MoveRight(float Value);
};
Paddle.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "Paddle.h"
#include "Components/InputComponent.h"
#include "GameFramework/FloatingPawnMovement.h"
// Sets default values
APaddle::APaddle()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
CreateDefaultSubobject<UFloatingPawnMovement>("PaddleMovement");
PaddleMesh = CreateDefaultSubobject<UStaticMeshComponent>("PaddleMesh");
}
// Called when the game starts or when spawned
void APaddle::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void APaddle::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void APaddle::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
//How to setup new axis mapping
PlayerInputComponent->BindAxis("Move", this, &APaddle::MoveRight);
}
void APaddle::MoveRight(float Value)
{
AddMovementInput(GetActorForwardVector(), Value);
}