Initial Project Setup
This commit is contained in:
34
Source/MyProject3/CameraFollowActor.cpp
Normal file
34
Source/MyProject3/CameraFollowActor.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// CameraFollowActor.cpp
|
||||
#include "CameraFollowActor.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
|
||||
// Sets default values
|
||||
ACameraFollowActor::ACameraFollowActor()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
// Create the camera component
|
||||
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
||||
RootComponent = CameraComponent;
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ACameraFollowActor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void ACameraFollowActor::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
if (TargetActor)
|
||||
{
|
||||
// Update the camera position to follow the target actor with the specified offset
|
||||
FVector NewLocation = TargetActor->GetActorLocation() + CameraOffset;
|
||||
SetActorLocation(NewLocation);
|
||||
}
|
||||
}
|
||||
36
Source/MyProject3/CameraFollowActor.h
Normal file
36
Source/MyProject3/CameraFollowActor.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// CameraFollowActor.h
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "CameraFollowActor.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class YOURPROJECT_API ACameraFollowActor : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
// Sets default values for this actor's properties
|
||||
ACameraFollowActor();
|
||||
|
||||
protected:
|
||||
// Called when the game starts or when spawned
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
// Called every frame
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
// The target actor that the camera will follow
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
|
||||
AActor* TargetActor;
|
||||
|
||||
// The offset from the target actor
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Camera")
|
||||
FVector CameraOffset;
|
||||
|
||||
private:
|
||||
UPROPERTY(VisibleAnywhere)
|
||||
UCameraComponent* CameraComponent;
|
||||
};
|
||||
99
Source/MyProject3/MyCharacter.cpp
Normal file
99
Source/MyProject3/MyCharacter.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "MyCharacter.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "GameFramework/Controller.h"
|
||||
#include "GameFramework/CharacterMovementComponent.h"
|
||||
|
||||
AMyCharacter::AMyCharacter()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
// 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
|
||||
|
||||
// Set base turn and look up rates
|
||||
BaseTurnRate = 45.0f;
|
||||
BaseLookUpRate = 45.0f;
|
||||
|
||||
// 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.0f;
|
||||
GetCharacterMovement()->AirControl = 0.2f;
|
||||
}
|
||||
|
||||
void AMyCharacter::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void AMyCharacter::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
}
|
||||
|
||||
void AMyCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
|
||||
PlayerInputComponent->BindAxis("MoveForward", this, &AMyCharacter::MoveForward);
|
||||
PlayerInputComponent->BindAxis("MoveRight", this, &AMyCharacter::MoveRight);
|
||||
|
||||
PlayerInputComponent->BindAxis("Turn", this, &APawn::AddControllerYawInput);
|
||||
PlayerInputComponent->BindAxis("TurnRate", this, &AMyCharacter::TurnAtRate);
|
||||
PlayerInputComponent->BindAxis("LookUp", this, &APawn::AddControllerPitchInput);
|
||||
PlayerInputComponent->BindAxis("LookUpRate", this, &AMyCharacter::LookUpAtRate);
|
||||
}
|
||||
|
||||
void AMyCharacter::MoveForward(float Value)
|
||||
{
|
||||
if ((Controller != nullptr) && (Value != 0.0f))
|
||||
{
|
||||
// find out 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 AMyCharacter::MoveRight(float Value)
|
||||
{
|
||||
if ((Controller != nullptr) && (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);
|
||||
AddMovementInput(Direction, Value);
|
||||
}
|
||||
}
|
||||
|
||||
void AMyCharacter::TurnAtRate(float Rate)
|
||||
{
|
||||
// calculate delta for this frame from the rate information
|
||||
AddControllerYawInput(Rate * BaseTurnRate * GetWorld()->GetDeltaSeconds());
|
||||
}
|
||||
|
||||
void AMyCharacter::LookUpAtRate(float Rate)
|
||||
{
|
||||
// calculate delta for this frame from the rate information
|
||||
AddControllerPitchInput(Rate * BaseLookUpRate * GetWorld()->GetDeltaSeconds());
|
||||
}
|
||||
39
Source/MyProject3/MyCharacter.h
Normal file
39
Source/MyProject3/MyCharacter.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "MyCharacter.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class YOURPROJECT_API AMyCharacter : public ACharacter
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AMyCharacter();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
public:
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
private:
|
||||
void MoveForward(float Value);
|
||||
void MoveRight(float Value);
|
||||
void TurnAtRate(float Rate);
|
||||
void LookUpAtRate(float Rate);
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
class USpringArmComponent* CameraBoom;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
class UCameraComponent* FollowCamera;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
float BaseTurnRate;
|
||||
|
||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
|
||||
float BaseLookUpRate;
|
||||
};
|
||||
8
Source/MyProject3/MyGameModeBase.cpp
Normal file
8
Source/MyProject3/MyGameModeBase.cpp
Normal file
@@ -0,0 +1,8 @@
|
||||
#include "MyGameMode.h"
|
||||
#include "MyCharacter.h"
|
||||
|
||||
AMyGameMode::AMyGameMode()
|
||||
{
|
||||
// Set default pawn class to our character class
|
||||
DefaultPawnClass = AMyCharacter::StaticClass();
|
||||
}
|
||||
14
Source/MyProject3/MyGameModeBase.h
Normal file
14
Source/MyProject3/MyGameModeBase.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "MyGameMode.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class YOURPROJECT_API AMyGameMode : public AGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AMyGameMode();
|
||||
};
|
||||
23
Source/MyProject3/MyProject3.Build.cs
Normal file
23
Source/MyProject3/MyProject3.Build.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
using UnrealBuildTool;
|
||||
|
||||
public class MyProject3 : ModuleRules
|
||||
{
|
||||
public MyProject3(ReadOnlyTargetRules Target) : base(Target)
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
|
||||
// Uncomment if you are using online features
|
||||
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
|
||||
|
||||
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
|
||||
}
|
||||
}
|
||||
6
Source/MyProject3/MyProject3.cpp
Normal file
6
Source/MyProject3/MyProject3.cpp
Normal file
@@ -0,0 +1,6 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#include "MyProject3.h"
|
||||
#include "Modules/ModuleManager.h"
|
||||
|
||||
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, MyProject3, "MyProject3" );
|
||||
6
Source/MyProject3/MyProject3.h
Normal file
6
Source/MyProject3/MyProject3.h
Normal file
@@ -0,0 +1,6 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
|
||||
5
Source/MyProject3/SpaceCraftHUD.cpp
Normal file
5
Source/MyProject3/SpaceCraftHUD.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "SpaceCraftHUD.h"
|
||||
|
||||
17
Source/MyProject3/SpaceCraftHUD.h
Normal file
17
Source/MyProject3/SpaceCraftHUD.h
Normal file
@@ -0,0 +1,17 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/HUD.h"
|
||||
#include "SpaceCraftHUD.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class MYPROJECT3_API ASpaceCraftHUD : public AHUD
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user