Guys i need Help, I’m used to do thing with bp, but I decided to try to learn c ++ so I started with the basics in ue4 that was to make a tps character, so i search on google tps tutorial but i cant find, then find this tutorial A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums , its outdate, but i managed to do with help of Vawx, now i finish the tutorial and my character doesn’t move, i cant look around, he just play idle animation
My problem is with (Adding a mesh to your Character) code, where i need change my
DefaultPawnClass = AFPSCharacter::StaticClass();
to
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT(
"Pawn'/Game/Blueprints/BP_FPSCharacter.BP_FPSCharacter_C'"
));
if (PlayerPawnObject.Class != NULL)
{
DefaultPawnClass = PlayerPawnObject.Class;
}
where is highlight i think is the problem
If you can help me, I would appreciate it.
Gamemode.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "GMode.h"
#include "MyChar.h"
#include "UObject/ConstructorHelpers.h"
AGMode::AGMode(const FObjectInitializer& FObjectInitializer)
: Super(FObjectInitializer)
{
//set default pawnclass to our blueprinted character
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("Pawn'/Game/char/BP_Mychar.BP_Mychar_C'"));
if (PlayerPawnObject.Class != NULL)
{
DefaultPawnClass = PlayerPawnObject.Class;
}
}
void AGMode::BeginPlay()
{
Super::BeginPlay();
StartPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Game Started"));
}
};
GameMode.h
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/GameModeBase.h"
#include "GMode.generated.h"
/**
*
*/
UCLASS()
class CTEST_API AGMode : public AGameModeBase
{
GENERATED_BODY()
AGMode(const FObjectInitializer& FobjectiInitializer);
virtual void BeginPlay() override;
};
MyChar.cpp
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyChar.h"
#include "Runtime/Engine/Classes/Camera/CameraComponent.h"
#include "Runtime/Engine/Classes/Camera/PlayerCameraManager.h"
#include "Runtime/Engine/Classes/Components/CapsuleComponent.h"
#include "Runtime/Engine/Classes/Components/SceneComponent.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h"
#include "Runtime/Engine/Classes/GameFramework/Character.h"
#include "GameFramework/CharacterMovementComponent.h"
// Sets default values
AMyChar::AMyChar()
{
// 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;
}
//Create Camera Component
AMyChar::AMyChar(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
//Create a Camera
ThirdPersonCameraComponent = ObjectInitializer.CreateDefaultSubobject<UCameraComponent>(this, TEXT("ThirdPersonCamera"));
ThirdPersonCameraComponent->AttachToComponent(GetRootComponent(), FAttachmentTransformRules::SnapToTargetNotIncludingScale, NAME_None);
//Allow Pawn Control Rotation
ThirdPersonCameraComponent->bUsePawnControlRotation = true;
}
// Called when the game starts or when spawned
void AMyChar::BeginPlay()
{
Super::BeginPlay();
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(-2, 5.f, FColor::Yellow, TEXT("My Character"));
}
}
// Called every frame
void AMyChar::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AMyChar::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
//setup gameplay key bindings
InputComponent->BindAxis("WS", this, &AMyChar::WS);
InputComponent->BindAxis("AD", this, &AMyChar::AD);
//setup gameplay mouse axis
InputComponent->BindAxis("Look Horiz", this, &AMyChar::AddControllerYawInput);
InputComponent->BindAxis("Look Ver", this, &AMyChar::AddControllerPitchInput);
//setup gameplay Jump key
InputComponent->BindAction("Jump", IE_Pressed, this, &AMyChar::OnStartJump);
InputComponent->BindAction("Jump", IE_Released, this, &AMyChar::OnStopJump);
}
void AMyChar::WS(float Value)
{
if ((Controller != NULL) && (Value != 0.0f))
{
// find out which way is forward
FRotator Rotation = Controller->GetControlRotation();
// Limit pitch when walking or falling
if (GetCharacterMovement()->IsMovingOnGround() || GetCharacterMovement()->IsFalling())
{
Rotation.Pitch = 0.0f;
}
// add movement in that direction
const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
AddMovementInput(Direction, Value);
}
}
void AMyChar::AD(float Value)
{
if ((Controller != NULL) && (Value != 0.0f))
{
// 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);
}
}
void AMyChar::OnStartJump()
{
bPressedJump = true;
}
void AMyChar::OnStopJump()
{
bPressedJump = false;
}
MyChar.h
#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "Runtime/Engine/Classes/Camera/CameraComponent.h"
#include "Runtime/Engine/Classes/Components/SceneComponent.h"
#include "Runtime/Engine/Classes/Components/InputComponent.h"
#include "MyChar.generated.h"
UCLASS()
class CTEST_API AMyChar : public ACharacter
{
GENERATED_BODY()
public:
// Sets defau values for this character's properties
AMyChar();
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;
//Move foward/backward
UFUNCTION()
virtual void WS(float val);
//Move strafe
UFUNCTION()
virtual void AD(float val);
//Set Jump flag when key is pressed
UFUNCTION()
void OnStartJump();
//Clear Jump flag when key is released
UFUNCTION()
void OnStopJump();
//Third Person Camera
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera)
UCameraComponent* ThirdPersonCameraComponent;
//Contructor for AMyChar
AMyChar(const FObjectInitializer& ObjectInitializer);
};