Third person setup Challenge: C++/Blueprints

Third person setup Challenge: C++/Blueprints

Third person setup Challenge: C++/Blueprints

Third person setup Challenge: C++/Blueprints es el cuarto reto propuesto por el curso Unreal Engine 4 Mastery: Create Multiplayer Games with C++ de Tom Looman certificado por Epic Games disponible en la plataforma Udemy.

A lo largo del curso se desarrollarán dos juegos con base en C++ y extendiendo la funcionalidad con Blueprints. Los dos juegos son multijugador y se profundizará también en AI y para reforzar los diferentes temas se proponen distintos retos.

En esta ocasión hay que crear de 0 en C++ el personaje principal, será con vista en tercera persona. Se tiene que agachar y  saltar y también se ha incorporado el Animation Starter Pack para las animaciones.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Character.h"
#include "SCharacter.generated.h"

class UCameraComponent;
class USpringArmComponent;

UCLASS()
class COOPGAME_API ASCharacter : public ACharacter
{
  GENERATED_BODY()

public:
  // Sets default values for this character's properties
  ASCharacter();

protected:
  // Called when the game starts or when spawned
  virtual void BeginPlay() override;

  void MoveForward(float Value);
  void MoveRight(float Value);

  void BeginCrouch();
  void EndCrouch();

  UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
  UCameraComponent* CameraComp;

  UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
  USpringArmComponent* SpringArmComp;

public: 
  // Called every frame
  virtual void Tick(float DeltaTime) override;

  // Called to bind functionality to input
  virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;

  
  
};
#include "../Public/SCharacter.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "GameFramework/PawnMovementComponent.h"

// Sets default values
ASCharacter::ASCharacter()
{
    // 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;

  SpringArmComp = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArmComp"));
  SpringArmComp->SetupAttachment(RootComponent);
  SpringArmComp->bUsePawnControlRotation = true;

  GetMovementComponent()->GetNavAgentPropertiesRef().bCanCrouch = true;

  CameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComp"));
  CameraComp->SetupAttachment(SpringArmComp);

}

// Called when the game starts or when spawned
void ASCharacter::BeginPlay()
{
  Super::BeginPlay();
  
}

void ASCharacter::MoveForward(float Value)
{
  AddMovementInput(GetActorForwardVector() * Value);
}

void ASCharacter::MoveRight(float Value)
{
  AddMovementInput(GetActorRightVector() * Value);
}

void ASCharacter::BeginCrouch()
{
  Crouch();
}

void ASCharacter::EndCrouch()
{
  UnCrouch();
}

// Called every frame
void ASCharacter::Tick(float DeltaTime)
{
  Super::Tick(DeltaTime);

}

// Called to bind functionality to input
void ASCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
  Super::SetupPlayerInputComponent(PlayerInputComponent);

  PlayerInputComponent->BindAxis("MoveForward", this, &ASCharacter::MoveForward);
  PlayerInputComponent->BindAxis("MoveRight", this, &ASCharacter::MoveRight);

  PlayerInputComponent->BindAxis("LooUp", this, &ASCharacter::AddControllerPitchInput);
  PlayerInputComponent->BindAxis("Turn", this, &ASCharacter::AddControllerYawInput);

  PlayerInputComponent->BindAction("Crouch", IE_Pressed, this, &ASCharacter::BeginCrouch);
  PlayerInputComponent->BindAction("Crouch", IE_Released, this, &ASCharacter::EndCrouch);

  PlayerInputComponent->BindAction("Jump", IE_Pressed, this, &ASCharacter::Jump);
}

A continuación os dejaré los enlaces al código, demo y al video en youtube para que podáis ver más. De momento me está gustando el curso pero al final compartiré una valoración general por si a alguien le pueda interesar que sepa más o menos que esperar del mismo.

Repositorio: Third person setup Challenge: C++/Blueprints [project]

Demo: Third person setup Challenge: C++/Blueprints [demo]

Curso: Unreal Engine 4 Mastery: Create Multiplayer Games with C++