Hey Everyone,
I’m very new to using unreal. My friends asked me to join them in making a game. I want to work as much in C++ as possible to improve my programming. So when i cloned the start of the game I found out that they began in the blueprint third person template. I created a character class and in in the ThirdPersonCharacter blueprint I re-parented to a c++ character class I had created. Now the character won’t move. I even copy and pasted the code created in the c++ 3rd person template and I still have no control.
here is the header:
#pragma once
#include "GameFramework/Character.h"
#include "DWCharacter.generated.h"
UCLASS()
class PROJECT_API ADWCharacter : public ACharacter
{
GENERATED_BODY()
//position camera behind player
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
//follow Camera
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;
public:
// Sets default values for this character's properties
ADWCharacter();
//base turn rate in degree per second
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
float BaseTurnRate;
//base look up rate in degree per second
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
float BaseLookUpRate;
// Called when the game starts or when spawned
virtual void BeginPlay() override;
// Called every frame
virtual void Tick( float DeltaSeconds ) override;
protected:
//move forward and backward
void MoveForward(float Value);
//move left and right
void MoveRight(float Value);
//rate of turning 1.0 is 100 percent turn rate
void TurnAtRate(float Rate);
//rate of looking up/down
void LookUpAtRate(float Rate);
//handler for beginning of touch input
void TouchStarted(ETouchIndex::Type FingerIndex, FVector Location);
//handler for when touchinput stops
void TouchStopped(ETouchIndex::Type FingerIndex, FVector Location);
protected:
//APawn interface
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
//end of pawn interface
public:
//returns CameraBoom
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
//returns FollowCamera
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
};
and the implementation:
#include "PROJECT.h"
#include "DWCharacter.h"
// Sets default values
ADWCharacter::ADWCharacter()
{
// 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;
// Set size for collision capsule
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
// set our turn rates for input
BaseTurnRate = 45.f;
BaseLookUpRate = 45.f;
// Don't rotate when the controller rotates. Let that just affect the camera.
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
// Configure character movement
GetCharacterMovement()->bOrientRotationToMovement = true; // Character moves in the direction of input...
GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f); // ...at this rotation rate
GetCharacterMovement()->JumpZVelocity = 600.f;
GetCharacterMovement()->AirControl = 0.2f;
// Create a camera boom (pulls in towards the player if there is a collision)
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 300.0f; // The camera follows at this distance behind the character
CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller
// Create a follow camera
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach the camera to the end of the boom and let the boom adjust to match the controller orientation
FollowCamera->bUsePawnControlRotation = false; // Camera does not rotate relative to arm
}
// Called when the game starts or when spawned
void ADWCharacter::BeginPlay()
{
Super::BeginPlay();
//debug message to make sure we are using the DWCharacter
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, TEXT("DWCharacter In Use."));
}
// Called every frame
void ADWCharacter::Tick( float DeltaTime )
{
Super::Tick( DeltaTime );
}
// Called to bind functionality to input
void ADWCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
// Set up gameplay key bindings
check(InputComponent);
InputComponent->BindAction("Jump", IE_Pressed, this, &ACharacter::Jump);
InputComponent->BindAction("Jump", IE_Released, this, &ACharacter::StopJumping);
InputComponent->BindAxis("MoveForward", this, &ADWCharacter::MoveForward);
InputComponent->BindAxis("MoveRight", this, &ADWCharacter::MoveRight);
// We have 2 versions of the rotation bindings to handle different kinds of devices differently
// "turn" handles devices that provide an absolute delta, such as a mouse.
// "turnrate" is for devices that we choose to treat as a rate of change, such as an analog joystick
InputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
InputComponent->BindAxis("TurnRate", this, &ADWCharacter::TurnAtRate);
InputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
InputComponent->BindAxis("LookUpRate", this, &ADWCharacter::LookUpAtRate);
// handle touch devices
InputComponent->BindTouch(IE_Pressed, this, &ADWCharacter::TouchStarted);
InputComponent->BindTouch(IE_Released, this, &ADWCharacter::TouchStopped);
}
void ADWCharacter::TouchStarted(ETouchIndex::Type FingerIndex, FVector Location)
{
//jump on the first touch
if (FingerIndex == ETouchIndex::Touch1)
{
Jump();
}
}
void ADWCharacter::TouchStopped(ETouchIndex::Type FingerIndex, FVector Location)
{
if (FingerIndex == ETouchIndex::Touch1)
{
StopJumping();
}
}
void ADWCharacter::TurnAtRate(float Rate)
{
//calculate delta for frame from rate info
AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
}
void ADWCharacter::LookUpAtRate(float Rate)
{
//calculate delta for frame from rate info
AddControllerPitchInput(Rate * BaseLookUpRate * GetWorld()->GetDeltaSeconds());
}
void ADWCharacter::MoveForward(float Value)
{
if ((Controller != NULL) && (Value != 0.0f))
{
//find which way is forward
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
//get forward vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
}
void ADWCharacter::MoveRight(float Value)
{
if ((Controller != NULL) && (Value != 0.0f))
{
//find out which way is right
const FRotator Rotation = Controller->GetControlRotation();
const FRotator YawRotation(0, Rotation.Yaw, 0);
//get right vector
const FVector Direction = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
//add movement in direction
AddMovementInput(Direction, Value);
}
}
any help would be greatly appreciated…I can’t seem to find a solution.
thank you