Compare commits
15 Commits
894f7c60c4
...
efce317da1
| Author | SHA1 | Date | |
|---|---|---|---|
| efce317da1 | |||
| 7653d26934 | |||
| 5ac7b648b9 | |||
| 561a9de8dd | |||
| 833edd7d8f | |||
| b3bbca282d | |||
| 482f386975 | |||
| 49895ec6a6 | |||
| 2519db2ced | |||
| 6fb1b648ec | |||
| 32365c408c | |||
| 4ee95ea366 | |||
| 536a938d55 | |||
| bb4d1bef59 | |||
| 07ed6f8876 |
@@ -6,4 +6,5 @@ bUseDistanceScaledCameraSpeed=True
|
||||
[ContentBrowser]
|
||||
ContentBrowserTab1.SourcesExpanded=True
|
||||
|
||||
[/Script/AdvancedPreviewScene.SharedProfiles]
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ bOffsetPlayerGamepadIds=False
|
||||
GameInstanceClass=/Script/Engine.GameInstance
|
||||
GameDefaultMap=/Engine/Maps/Templates/OpenWorld.OpenWorld
|
||||
ServerDefaultMap=/Engine/Maps/Entry.Entry
|
||||
GlobalDefaultGameMode=/Game/StarterContent/Blueprints/Deathmatch.Deathmatch_C
|
||||
GlobalDefaultGameMode=/Game/Blueprints/BP_SpaceShooterGameMode.BP_SpaceShooterGameMode_C
|
||||
GlobalDefaultServerGameMode=None
|
||||
|
||||
[/Script/UnrealEd.UnrealEdEngine]
|
||||
|
||||
BIN
Content/Blueprints/BP_EnemySpaceship.uasset
LFS
Normal file
BIN
Content/Blueprints/BP_EnemySpaceship.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Blueprints/BP_SpaceShooterGameMode.uasset
LFS
Normal file
BIN
Content/Blueprints/BP_SpaceShooterGameMode.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Blueprints/BP_SpaceshipPawn.uasset
LFS
Normal file
BIN
Content/Blueprints/BP_SpaceshipPawn.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Blueprints/BP_SpaceshipProjectile.uasset
LFS
Normal file
BIN
Content/Blueprints/BP_SpaceshipProjectile.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Environment.umap
LFS
Normal file
BIN
Content/Environment.umap
LFS
Normal file
Binary file not shown.
BIN
Content/EnvironmentAssests/Asteriods/Blueprint/BP_AsteriodBase.uasset
LFS
Normal file
BIN
Content/EnvironmentAssests/Asteriods/Blueprint/BP_AsteriodBase.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/EnvironmentAssests/Asteriods/Blueprint/BP_AsteriodSpawnManager.uasset
LFS
Normal file
BIN
Content/EnvironmentAssests/Asteriods/Blueprint/BP_AsteriodSpawnManager.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/EnvironmentAssests/Asteriods/Meshes/70_stylized_rocks_texture_17.uasset
LFS
Normal file
BIN
Content/EnvironmentAssests/Asteriods/Meshes/70_stylized_rocks_texture_17.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/EnvironmentAssests/Asteriods/Meshes/Object_19.uasset
LFS
Normal file
BIN
Content/EnvironmentAssests/Asteriods/Meshes/Object_19.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/EnvironmentAssests/Asteriods/Meshes/stylized_rock_18.uasset
LFS
Normal file
BIN
Content/EnvironmentAssests/Asteriods/Meshes/stylized_rock_18.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Input/IA_Fire.uasset
LFS
Normal file
BIN
Content/Input/IA_Fire.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Input/IA_MouseControl.uasset
LFS
Normal file
BIN
Content/Input/IA_MouseControl.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Input/IA_MouseLook.uasset
LFS
Normal file
BIN
Content/Input/IA_MouseLook.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Input/IA_Movement.uasset
LFS
Normal file
BIN
Content/Input/IA_Movement.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Input/IA_Throttle.uasset
LFS
Normal file
BIN
Content/Input/IA_Throttle.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Input/IMC_Spaceship.uasset
LFS
Normal file
BIN
Content/Input/IMC_Spaceship.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Main.umap
LFS
BIN
Content/Main.umap
LFS
Binary file not shown.
BIN
Content/Materials/M_StarSparrow_Blue.uasset
LFS
Normal file
BIN
Content/Materials/M_StarSparrow_Blue.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Materials/M_StarSparrow_Green.uasset
LFS
Normal file
BIN
Content/Materials/M_StarSparrow_Green.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Materials/M_StarSparrow_Grey.uasset
LFS
Normal file
BIN
Content/Materials/M_StarSparrow_Grey.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Materials/M_StarSparrow_Purple.uasset
LFS
Normal file
BIN
Content/Materials/M_StarSparrow_Purple.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Materials/M_StarSparrow_Red.uasset
LFS
Normal file
BIN
Content/Materials/M_StarSparrow_Red.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Materials/M_StarSparrow_White.uasset
LFS
Normal file
BIN
Content/Materials/M_StarSparrow_White.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Meshes/SM_StarSparrow01.uasset
LFS
Normal file
BIN
Content/Meshes/SM_StarSparrow01.uasset
LFS
Normal file
Binary file not shown.
BIN
Content/Meshes/SM_StarSparrow02.uasset
LFS
Normal file
BIN
Content/Meshes/SM_StarSparrow02.uasset
LFS
Normal file
Binary file not shown.
@@ -1,4 +1,4 @@
|
||||
# Simulator Project
|
||||
# Simulator Game Project
|
||||
|
||||
## Overview
|
||||
A spaceship simulator game developed in Unreal Engine 5, focusing on realistic physics and comprehensive ship systems management. Players control a fully simulated spacecraft with integrated power, navigation, and damage systems.
|
||||
@@ -22,7 +22,7 @@ A spaceship simulator game developed in Unreal Engine 5, focusing on realistic p
|
||||
### Installation
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://github.com/YourUsername/SpaceshipSimulator.git
|
||||
git clone https://git.cinis.cf/Ludusphere/Yamato.git
|
||||
```
|
||||
|
||||
2. Initialize and update Git LFS:
|
||||
@@ -95,8 +95,8 @@ git checkout -b feature/your-feature-name
|
||||
5. Create a Pull Request
|
||||
|
||||
## Project Team
|
||||
- Person A: Core Systems Developer
|
||||
- Person B: Content and Design Developer
|
||||
- Aiden Correya: Core Systems Developer
|
||||
- Shashank Kumar: Content and Design Developer
|
||||
|
||||
## License
|
||||
- To be decided
|
||||
|
||||
92
Source/MyProject3/EnemySpaceship.cpp
Normal file
92
Source/MyProject3/EnemySpaceship.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
#include "EnemySpaceship.h"
|
||||
#include "SpaceshipPawn.h"
|
||||
#include "SpaceshipProjectile.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
AEnemySpaceship::AEnemySpaceship()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
ShipMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ShipMesh"));
|
||||
RootComponent = ShipMesh;
|
||||
|
||||
CurrentHealth = MaxHealth;
|
||||
}
|
||||
|
||||
void AEnemySpaceship::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
PlayerPawn = Cast<ASpaceshipPawn>(UGameplayStatics::GetPlayerPawn(GetWorld(), 0));
|
||||
GetWorldTimerManager().SetTimer(FireTimerHandle, this, &AEnemySpaceship::FireAtPlayer, FireRate, true);
|
||||
}
|
||||
|
||||
void AEnemySpaceship::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
if (PlayerPawn)
|
||||
{
|
||||
// Calculate distance to player
|
||||
float DistanceToPlayer = FVector::Dist(GetActorLocation(), PlayerPawn->GetActorLocation());
|
||||
|
||||
if (DistanceToPlayer <= DetectionRange)
|
||||
{
|
||||
// Look at player
|
||||
FVector Direction = PlayerPawn->GetActorLocation() - GetActorLocation();
|
||||
FRotator NewRotation = Direction.Rotation();
|
||||
SetActorRotation(FMath::RInterpTo(GetActorRotation(), NewRotation, DeltaTime, 2.0f));
|
||||
|
||||
// Move towards player while maintaining some distance
|
||||
float TargetDistance = 1000.0f;
|
||||
if (DistanceToPlayer > TargetDistance)
|
||||
{
|
||||
FVector NewLocation = GetActorLocation() + (Direction.GetSafeNormal() * MovementSpeed * DeltaTime);
|
||||
SetActorLocation(NewLocation);
|
||||
}
|
||||
else if (DistanceToPlayer < TargetDistance - 100.0f)
|
||||
{
|
||||
FVector NewLocation = GetActorLocation() - (Direction.GetSafeNormal() * MovementSpeed * DeltaTime);
|
||||
SetActorLocation(NewLocation);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AEnemySpaceship::FireAtPlayer()
|
||||
{
|
||||
if (PlayerPawn && FVector::Dist(GetActorLocation(), PlayerPawn->GetActorLocation()) <= DetectionRange)
|
||||
{
|
||||
UWorld* World = GetWorld();
|
||||
if (World)
|
||||
{
|
||||
FVector SpawnLocation = GetActorLocation() + (GetActorForwardVector() * 100.0f);
|
||||
FRotator SpawnRotation = GetActorRotation();
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.Owner = this;
|
||||
SpawnParams.Instigator = GetInstigator();
|
||||
|
||||
ASpaceshipProjectile* Projectile = World->SpawnActor<ASpaceshipProjectile>(
|
||||
ASpaceshipProjectile::StaticClass(),
|
||||
SpawnLocation,
|
||||
SpawnRotation,
|
||||
SpawnParams
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float AEnemySpaceship::TakeDamage(float Damage, FDamageEvent const& DamageEvent,
|
||||
AController* EventInstigator, AActor* DamageCauser)
|
||||
{
|
||||
float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser);
|
||||
|
||||
CurrentHealth -= ActualDamage;
|
||||
if (CurrentHealth <= 0)
|
||||
{
|
||||
// Destroy the enemy ship
|
||||
Destroy();
|
||||
}
|
||||
|
||||
return ActualDamage;
|
||||
}
|
||||
41
Source/MyProject3/EnemySpaceship.h
Normal file
41
Source/MyProject3/EnemySpaceship.h
Normal file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Pawn.h"
|
||||
#include "EnemySpaceship.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class MYPROJECT3_API AEnemySpaceship : public APawn
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AEnemySpaceship();
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
|
||||
class UStaticMeshComponent* ShipMesh;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
|
||||
float DetectionRange = 1500.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AI")
|
||||
float FireRate = 2.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
|
||||
float MovementSpeed = 500.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Combat")
|
||||
float MaxHealth = 100.0f;
|
||||
|
||||
float CurrentHealth;
|
||||
FTimerHandle FireTimerHandle;
|
||||
class ASpaceshipPawn* PlayerPawn;
|
||||
|
||||
void FireAtPlayer();
|
||||
virtual float TakeDamage(float Damage, struct FDamageEvent const& DamageEvent,
|
||||
AController* EventInstigator, AActor* DamageCauser) override;
|
||||
};
|
||||
@@ -10,7 +10,7 @@ public class MyProject3 : ModuleRules
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { "EnhancedInput" });
|
||||
|
||||
// Uncomment if you are using Slate UI
|
||||
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
|
||||
|
||||
88
Source/MyProject3/SpaceShooterGameMode.cpp
Normal file
88
Source/MyProject3/SpaceShooterGameMode.cpp
Normal file
@@ -0,0 +1,88 @@
|
||||
#include "SpaceShooterGameMode.h"
|
||||
#include "SpaceshipPawn.h"
|
||||
#include "EnemySpaceship.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
ASpaceShooterGameMode::ASpaceShooterGameMode()
|
||||
{
|
||||
// Set default pawn class using the inherited DefaultPawnClass
|
||||
static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/Blueprints/BP_SpaceshipPawn"));
|
||||
if (PlayerPawnBPClass.Class != nullptr)
|
||||
{
|
||||
DefaultPawnClass = PlayerPawnBPClass.Class;
|
||||
}
|
||||
|
||||
// Enable Tick()
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
// Debug message
|
||||
if (GEngine)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("GameMode Constructor"));
|
||||
}
|
||||
}
|
||||
|
||||
void ASpaceShooterGameMode::StartPlay()
|
||||
{
|
||||
Super::StartPlay();
|
||||
|
||||
// Start spawning enemies
|
||||
GetWorldTimerManager().SetTimer(EnemySpawnTimer, this, &ASpaceShooterGameMode::SpawnEnemy,
|
||||
EnemySpawnInterval, true);
|
||||
|
||||
// Debug message
|
||||
if (GEngine)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Green, TEXT("GameMode StartPlay"));
|
||||
}
|
||||
}
|
||||
|
||||
void ASpaceShooterGameMode::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
}
|
||||
|
||||
void ASpaceShooterGameMode::SpawnEnemy()
|
||||
{
|
||||
// Count current enemies
|
||||
TArray<AActor*> FoundEnemies;
|
||||
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AEnemySpaceship::StaticClass(), FoundEnemies);
|
||||
|
||||
// Only spawn if we haven't reached the maximum
|
||||
if (FoundEnemies.Num() < MaxEnemies)
|
||||
{
|
||||
UWorld* World = GetWorld();
|
||||
if (World)
|
||||
{
|
||||
FVector SpawnLocation = GetRandomSpawnLocation();
|
||||
FRotator SpawnRotation = FRotator::ZeroRotator;
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButAlwaysSpawn;
|
||||
|
||||
World->SpawnActor<AEnemySpaceship>(AEnemySpaceship::StaticClass(), SpawnLocation,
|
||||
SpawnRotation, SpawnParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FVector ASpaceShooterGameMode::GetRandomSpawnLocation()
|
||||
{
|
||||
APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
|
||||
if (PlayerController && PlayerController->GetPawn())
|
||||
{
|
||||
FVector PlayerLocation = PlayerController->GetPawn()->GetActorLocation();
|
||||
|
||||
// Generate random angle
|
||||
float Angle = FMath::RandRange(0.0f, 2.0f * PI);
|
||||
|
||||
// Calculate spawn position in a circle around the player
|
||||
FVector SpawnLocation;
|
||||
SpawnLocation.X = PlayerLocation.X + SpawnRadius * FMath::Cos(Angle);
|
||||
SpawnLocation.Y = PlayerLocation.Y + SpawnRadius * FMath::Sin(Angle);
|
||||
SpawnLocation.Z = PlayerLocation.Z;
|
||||
|
||||
return SpawnLocation;
|
||||
}
|
||||
|
||||
return FVector::ZeroVector;
|
||||
}
|
||||
32
Source/MyProject3/SpaceShooterGameMode.h
Normal file
32
Source/MyProject3/SpaceShooterGameMode.h
Normal file
@@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "SpaceShooterGameMode.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class MYPROJECT3_API ASpaceShooterGameMode : public AGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ASpaceShooterGameMode();
|
||||
|
||||
virtual void StartPlay() override;
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
|
||||
protected:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
|
||||
float EnemySpawnInterval = 3.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
|
||||
float SpawnRadius = 2000.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Spawning")
|
||||
int32 MaxEnemies = 5;
|
||||
|
||||
private:
|
||||
FTimerHandle EnemySpawnTimer;
|
||||
void SpawnEnemy();
|
||||
FVector GetRandomSpawnLocation();
|
||||
};
|
||||
232
Source/MyProject3/SpaceshipPawn.cpp
Normal file
232
Source/MyProject3/SpaceshipPawn.cpp
Normal file
@@ -0,0 +1,232 @@
|
||||
#include "SpaceshipPawn.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "Components/StaticMeshComponent.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "SpaceshipProjectile.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "GameFramework/GameUserSettings.h"
|
||||
|
||||
|
||||
ASpaceshipPawn::ASpaceshipPawn()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
// Create ship mesh
|
||||
ShipMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ShipMesh"));
|
||||
RootComponent = ShipMesh;
|
||||
ShipMesh->SetSimulatePhysics(false);
|
||||
ShipMesh->SetEnableGravity(false);
|
||||
|
||||
// Create camera spring arm
|
||||
CameraSpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
|
||||
CameraSpringArm->SetupAttachment(RootComponent);
|
||||
CameraSpringArm->TargetArmLength = 400.0f;
|
||||
CameraSpringArm->bEnableCameraLag = true;
|
||||
CameraSpringArm->CameraLagSpeed = 10.0f;
|
||||
CameraSpringArm->bEnableCameraRotationLag = true;
|
||||
CameraSpringArm->CameraRotationLagSpeed = 10.0f;
|
||||
CameraSpringArm->CameraLagMaxDistance = 7.0f;
|
||||
CameraSpringArm->bUsePawnControlRotation = false; // Add this line
|
||||
CameraSpringArm->bInheritPitch = true; // Add this line
|
||||
CameraSpringArm->bInheritYaw = true; // Add this line
|
||||
CameraSpringArm->bInheritRoll = false; // Add this line
|
||||
|
||||
// Create camera
|
||||
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
|
||||
Camera->SetupAttachment(CameraSpringArm, USpringArmComponent::SocketName);
|
||||
|
||||
// Initialize movement variables
|
||||
CurrentThrust = 0.0f;
|
||||
TargetThrust = 0.0f;
|
||||
bThrottlePressed = false;
|
||||
CurrentVelocity = FVector::ZeroVector;
|
||||
CurrentPitch = 0.0f;
|
||||
CurrentYaw = 0.0f;
|
||||
TargetRotation = FRotator::ZeroRotator;
|
||||
LastMouseDelta = FVector2D::ZeroVector;
|
||||
}
|
||||
|
||||
void ASpaceshipPawn::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
|
||||
// Store player controller reference
|
||||
PlayerControllerRef = Cast<APlayerController>(Controller);
|
||||
|
||||
if (PlayerControllerRef)
|
||||
{
|
||||
// Setup input mapping context
|
||||
if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(PlayerControllerRef->GetLocalPlayer()))
|
||||
{
|
||||
Subsystem->AddMappingContext(DefaultMappingContext, 0);
|
||||
}
|
||||
|
||||
// Setup mouse capture and fullscreen
|
||||
PlayerControllerRef->SetShowMouseCursor(false);
|
||||
PlayerControllerRef->SetInputMode(FInputModeGameOnly());
|
||||
|
||||
// Request fullscreen mode using GameUserSettings
|
||||
UGameUserSettings* GameUserSettings = UGameUserSettings::GetGameUserSettings();
|
||||
if (GameUserSettings)
|
||||
{
|
||||
GameUserSettings->SetFullscreenMode(EWindowMode::Fullscreen);
|
||||
GameUserSettings->SetScreenResolution(FIntPoint(1920, 1080)); // Adjust the resolution if needed
|
||||
GameUserSettings->ApplySettings(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ASpaceshipPawn::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
// Handle thrust
|
||||
if (!bThrottlePressed)
|
||||
{
|
||||
CurrentThrust = FMath::FInterpTo(CurrentThrust, 0.0f, DeltaTime, ThrustDeceleration);
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentThrust = FMath::FInterpTo(CurrentThrust, TargetThrust, DeltaTime, ThrustAcceleration);
|
||||
}
|
||||
|
||||
// Update movement based on ship's forward vector
|
||||
FVector ThrustDirection = GetActorForwardVector();
|
||||
FVector ThrustForce = ThrustDirection * CurrentThrust;
|
||||
|
||||
// Apply drag
|
||||
FVector DragForce = -CurrentVelocity * DragCoefficient;
|
||||
|
||||
// Update velocity
|
||||
CurrentVelocity += (ThrustForce + DragForce) * DeltaTime;
|
||||
|
||||
// Update position
|
||||
FVector NewLocation = GetActorLocation() + (CurrentVelocity * DeltaTime);
|
||||
SetActorLocation(NewLocation, true);
|
||||
|
||||
// Debug info
|
||||
if (GEngine)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Yellow,
|
||||
FString::Printf(TEXT("Thrust: %.2f"), CurrentThrust));
|
||||
GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Green,
|
||||
FString::Printf(TEXT("Velocity: %.2f"), CurrentVelocity.Size()));
|
||||
}
|
||||
|
||||
// Smooth mouse movement
|
||||
MouseDeltaSmoothed = FMath::Vector2DInterpTo(
|
||||
MouseDeltaSmoothed,
|
||||
LastMouseDelta,
|
||||
DeltaTime,
|
||||
MouseSmoothingSpeed
|
||||
);
|
||||
|
||||
// Update rotation based on smoothed mouse movement
|
||||
CurrentYaw += MouseDeltaSmoothed.X * MouseSensitivity * DeltaTime * 60.0f; // Multiply by 60 to normalize for frame rate
|
||||
CurrentPitch = FMath::ClampAngle(
|
||||
CurrentPitch + (MouseDeltaSmoothed.Y * MouseSensitivity * DeltaTime * 60.0f),
|
||||
-85.0f,
|
||||
85.0f
|
||||
);
|
||||
|
||||
// Set target rotation
|
||||
TargetRotation = FRotator(CurrentPitch, CurrentYaw, 0.0f);
|
||||
|
||||
// Smoothly interpolate to target rotation using quaternions for better interpolation
|
||||
FQuat CurrentQuat = GetActorQuat();
|
||||
FQuat TargetQuat = TargetRotation.Quaternion();
|
||||
FQuat NewQuat = FQuat::Slerp(CurrentQuat, TargetQuat, RotationSpeed * DeltaTime);
|
||||
SetActorRotation(NewQuat);
|
||||
|
||||
// Update spring arm rotation to match ship with smooth interpolation
|
||||
if (CameraSpringArm)
|
||||
{
|
||||
FRotator SpringArmRotation = CameraSpringArm->GetComponentRotation();
|
||||
FRotator TargetSpringArmRotation = NewQuat.Rotator();
|
||||
FRotator NewSpringArmRotation = FMath::RInterpTo(
|
||||
SpringArmRotation,
|
||||
TargetSpringArmRotation,
|
||||
DeltaTime,
|
||||
RotationSpeed
|
||||
);
|
||||
CameraSpringArm->SetWorldRotation(NewSpringArmRotation);
|
||||
}
|
||||
|
||||
// Reset mouse delta for next frame
|
||||
LastMouseDelta = FVector2D::ZeroVector;
|
||||
|
||||
// Debug info
|
||||
if (GEngine)
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Yellow,
|
||||
FString::Printf(TEXT("Smoothed Mouse Delta: X=%.2f Y=%.2f"), MouseDeltaSmoothed.X, MouseDeltaSmoothed.Y));
|
||||
GEngine->AddOnScreenDebugMessage(-1, 0.0f, FColor::Green,
|
||||
FString::Printf(TEXT("Current Rotation: P=%.2f Y=%.2f"), CurrentPitch, CurrentYaw));
|
||||
}
|
||||
}
|
||||
|
||||
void ASpaceshipPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
|
||||
{
|
||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||
|
||||
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(PlayerInputComponent))
|
||||
{
|
||||
// Bind both Hold and Released events for throttle
|
||||
EnhancedInputComponent->BindAction(ThrottleAction, ETriggerEvent::Started, this, &ASpaceshipPawn::HandleThrottleStarted);
|
||||
EnhancedInputComponent->BindAction(ThrottleAction, ETriggerEvent::Completed, this, &ASpaceshipPawn::HandleThrottleReleased);
|
||||
|
||||
// Bind mouse control
|
||||
EnhancedInputComponent->BindAction(MouseLookAction, ETriggerEvent::Triggered, this, &ASpaceshipPawn::HandleMouseLook);
|
||||
|
||||
// Bind fire action
|
||||
EnhancedInputComponent->BindAction(FireAction, ETriggerEvent::Triggered, this, &ASpaceshipPawn::HandleFire);
|
||||
}
|
||||
}
|
||||
|
||||
// Split the throttle handling into two functions
|
||||
void ASpaceshipPawn::HandleThrottleStarted(const FInputActionValue& Value)
|
||||
{
|
||||
const float ThrottleValue = Value.Get<float>();
|
||||
bThrottlePressed = true;
|
||||
TargetThrust = ThrottleValue * MaxThrust;
|
||||
}
|
||||
|
||||
void ASpaceshipPawn::HandleThrottleReleased(const FInputActionValue& Value)
|
||||
{
|
||||
bThrottlePressed = false;
|
||||
}
|
||||
|
||||
void ASpaceshipPawn::HandleMouseLook(const FInputActionValue& Value)
|
||||
{
|
||||
const FVector2D MouseDelta = Value.Get<FVector2D>();
|
||||
|
||||
// Smoothly interpolate mouse delta
|
||||
LastMouseDelta = MouseDelta;
|
||||
}
|
||||
|
||||
void ASpaceshipPawn::HandleFire(const FInputActionValue& Value)
|
||||
{
|
||||
UWorld* World = GetWorld();
|
||||
if (World)
|
||||
{
|
||||
FVector SpawnLocation = ShipMesh->GetSocketLocation(TEXT("ProjectileSpawn"));
|
||||
if (SpawnLocation == FVector::ZeroVector)
|
||||
{
|
||||
SpawnLocation = GetActorLocation() + (GetActorForwardVector() * 100.0f);
|
||||
}
|
||||
|
||||
FRotator SpawnRotation = GetActorRotation();
|
||||
FActorSpawnParameters SpawnParams;
|
||||
SpawnParams.Owner = this;
|
||||
SpawnParams.Instigator = GetInstigator();
|
||||
|
||||
World->SpawnActor<ASpaceshipProjectile>(
|
||||
ASpaceshipProjectile::StaticClass(),
|
||||
SpawnLocation,
|
||||
SpawnRotation,
|
||||
SpawnParams
|
||||
);
|
||||
}
|
||||
}
|
||||
84
Source/MyProject3/SpaceshipPawn.h
Normal file
84
Source/MyProject3/SpaceshipPawn.h
Normal file
@@ -0,0 +1,84 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Pawn.h"
|
||||
#include "InputActionValue.h"
|
||||
#include "SpaceshipPawn.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class MYPROJECT3_API ASpaceshipPawn : public APawn
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ASpaceshipPawn();
|
||||
virtual void Tick(float DeltaTime) override;
|
||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
// Components
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
|
||||
class UStaticMeshComponent* ShipMesh;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
|
||||
class USpringArmComponent* CameraSpringArm;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
|
||||
class UCameraComponent* Camera;
|
||||
|
||||
// Enhanced Input Components
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputMappingContext* DefaultMappingContext;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* ThrottleAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* MouseLookAction;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
|
||||
class UInputAction* FireAction;
|
||||
|
||||
// Movement Parameters
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
|
||||
float MaxThrust = 2000.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
|
||||
float ThrustAcceleration = 500.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
|
||||
float ThrustDeceleration = 500.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
|
||||
float RotationSpeed = 100.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
|
||||
float MouseSensitivity = 2.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Movement")
|
||||
float DragCoefficient = 0.05f;
|
||||
|
||||
// Input functions
|
||||
void HandleThrottleStarted(const FInputActionValue& Value);
|
||||
void HandleThrottleReleased(const FInputActionValue& Value);
|
||||
void HandleMouseLook(const FInputActionValue& Value);
|
||||
void HandleFire(const FInputActionValue& Value);
|
||||
|
||||
private:
|
||||
// Movement state
|
||||
float CurrentThrust;
|
||||
float TargetThrust;
|
||||
bool bThrottlePressed;
|
||||
FVector CurrentVelocity;
|
||||
FRotator TargetRotation;
|
||||
|
||||
float CurrentPitch;
|
||||
float CurrentYaw;
|
||||
APlayerController* PlayerControllerRef;
|
||||
|
||||
FVector2D MouseDeltaSmoothed;
|
||||
FVector2D LastMouseDelta;
|
||||
float MouseSmoothingSpeed = 10.0f;
|
||||
};
|
||||
43
Source/MyProject3/SpaceshipProjectile.cpp
Normal file
43
Source/MyProject3/SpaceshipProjectile.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "SpaceshipProjectile.h"
|
||||
#include "GameFramework/ProjectileMovementComponent.h"
|
||||
#include "Components/StaticMeshComponent.h"
|
||||
|
||||
ASpaceshipProjectile::ASpaceshipProjectile()
|
||||
{
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
// Create and setup the projectile mesh
|
||||
ProjectileMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("ProjectileMesh"));
|
||||
RootComponent = ProjectileMesh;
|
||||
ProjectileMesh->SetCollisionProfileName(TEXT("Projectile"));
|
||||
ProjectileMesh->OnComponentHit.AddDynamic(this, &ASpaceshipProjectile::OnHit);
|
||||
|
||||
// Create and setup projectile movement
|
||||
ProjectileMovement = CreateDefaultSubobject<UProjectileMovementComponent>(TEXT("ProjectileMovement"));
|
||||
ProjectileMovement->UpdatedComponent = ProjectileMesh;
|
||||
ProjectileMovement->InitialSpeed = ProjectileSpeed;
|
||||
ProjectileMovement->MaxSpeed = ProjectileSpeed;
|
||||
ProjectileMovement->bRotationFollowsVelocity = true;
|
||||
ProjectileMovement->ProjectileGravityScale = 0.0f;
|
||||
|
||||
// Set lifetime
|
||||
InitialLifeSpan = 3.0f;
|
||||
}
|
||||
|
||||
void ASpaceshipProjectile::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
void ASpaceshipProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
FVector NormalImpulse, const FHitResult& Hit)
|
||||
{
|
||||
if (OtherActor && OtherActor != this)
|
||||
{
|
||||
// Apply damage to the hit actor (if it implements damage interface)
|
||||
FDamageEvent DamageEvent;
|
||||
OtherActor->TakeDamage(DamageAmount, DamageEvent, nullptr, this);
|
||||
}
|
||||
|
||||
Destroy();
|
||||
}
|
||||
33
Source/MyProject3/SpaceshipProjectile.h
Normal file
33
Source/MyProject3/SpaceshipProjectile.h
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
#include "SpaceshipProjectile.generated.h"
|
||||
|
||||
UCLASS()
|
||||
class MYPROJECT3_API ASpaceshipProjectile : public AActor
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
ASpaceshipProjectile();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
|
||||
class UStaticMeshComponent* ProjectileMesh;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Components")
|
||||
class UProjectileMovementComponent* ProjectileMovement;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
|
||||
float ProjectileSpeed = 3000.0f;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Projectile")
|
||||
float DamageAmount = 20.0f;
|
||||
|
||||
UFUNCTION()
|
||||
void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp,
|
||||
FVector NormalImpulse, const FHitResult& Hit);
|
||||
};
|
||||
Reference in New Issue
Block a user