From 84a981a6739dd4418e3b99cb4f688f237b8f44bb Mon Sep 17 00:00:00 2001 From: Rafal <34179rs@gmail.com> Date: Wed, 2 Oct 2024 21:13:20 +0100 Subject: [PATCH] Removed TP Classes and Created Pilot Camera --- .../Blueprints/BP_FirstPersonCharacter.uasset | 4 +- .../BP_FirstPersonPlayerController.uasset | 4 +- .../Blueprints/BP_PickUp_Rifle.uasset | 4 +- .../A/KU/12YG9I1QW2GU72MG8QQX1K.uasset | 4 +- Monolith.uproject | 5 +- Source/Monolith/MonolithCharacter.cpp | 6 +- Source/Monolith/MonolithCharacter.h | 9 +- Source/Monolith/MonolithProjectile.cpp | 43 ------- Source/Monolith/MonolithProjectile.h | 37 ------ Source/Monolith/PilotCamera.cpp | 23 ++++ Source/Monolith/PilotCamera.h | 21 ++++ Source/Monolith/TP_PickUpComponent.cpp | 31 ----- Source/Monolith/TP_PickUpComponent.h | 34 ----- Source/Monolith/TP_WeaponComponent.cpp | 119 ------------------ Source/Monolith/TP_WeaponComponent.h | 60 --------- 15 files changed, 63 insertions(+), 341 deletions(-) delete mode 100644 Source/Monolith/MonolithProjectile.cpp delete mode 100644 Source/Monolith/MonolithProjectile.h create mode 100644 Source/Monolith/PilotCamera.cpp create mode 100644 Source/Monolith/PilotCamera.h delete mode 100644 Source/Monolith/TP_PickUpComponent.cpp delete mode 100644 Source/Monolith/TP_PickUpComponent.h delete mode 100644 Source/Monolith/TP_WeaponComponent.cpp delete mode 100644 Source/Monolith/TP_WeaponComponent.h diff --git a/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 51a3e9d..323855d 100644 --- a/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset +++ b/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f97b3577d7075e2885dc8de9f27a9b0a93bf1ed4ee6ebbccd7f19f470739d7a0 -size 23260 +oid sha256:143c7d036d0cfe8c8519a3eb1a994db945f239f9f1a4fbfdc70e2f13fdf4579c +size 25994 diff --git a/Content/FirstPerson/Blueprints/BP_FirstPersonPlayerController.uasset b/Content/FirstPerson/Blueprints/BP_FirstPersonPlayerController.uasset index 9f5569d..4c9aa22 100644 --- a/Content/FirstPerson/Blueprints/BP_FirstPersonPlayerController.uasset +++ b/Content/FirstPerson/Blueprints/BP_FirstPersonPlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7515f9e673affad4be6df1b5953a7204518efad1686c3465b7d4396981576f08 -size 14271 +oid sha256:d70106cea0694d806c23054ca753de593dff86ea91e800ef006627e9ed1d7c7b +size 14807 diff --git a/Content/FirstPerson/Blueprints/BP_PickUp_Rifle.uasset b/Content/FirstPerson/Blueprints/BP_PickUp_Rifle.uasset index 0fecfcf..6008908 100644 --- a/Content/FirstPerson/Blueprints/BP_PickUp_Rifle.uasset +++ b/Content/FirstPerson/Blueprints/BP_PickUp_Rifle.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e96ef0d21d518ba914366f0570b1e942f9c12b8a88b3ba5e6adc02ff80589fbb -size 50236 +oid sha256:13910fd4fb746d952144fd27f931199494128ef0efb9fdb9075466f56f802a8a +size 18651 diff --git a/Content/__ExternalActors__/FirstPerson/Maps/FirstPersonMap/A/KU/12YG9I1QW2GU72MG8QQX1K.uasset b/Content/__ExternalActors__/FirstPerson/Maps/FirstPersonMap/A/KU/12YG9I1QW2GU72MG8QQX1K.uasset index 1d1c7bf..aa889de 100644 --- a/Content/__ExternalActors__/FirstPerson/Maps/FirstPersonMap/A/KU/12YG9I1QW2GU72MG8QQX1K.uasset +++ b/Content/__ExternalActors__/FirstPerson/Maps/FirstPersonMap/A/KU/12YG9I1QW2GU72MG8QQX1K.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:89d3f2224b7ea719774a0267affaf6b64051cd86a54c04c054b583b5e21a13e2 -size 4607 +oid sha256:151288d7cdf683f67a702e845031cb1348379507bcebfd2b3375df6b74be511b +size 5070 diff --git a/Monolith.uproject b/Monolith.uproject index b82a865..c45ff17 100644 --- a/Monolith.uproject +++ b/Monolith.uproject @@ -7,7 +7,10 @@ { "Name": "Monolith", "Type": "Runtime", - "LoadingPhase": "Default" + "LoadingPhase": "Default", + "AdditionalDependencies": [ + "Engine" + ] } ], "Plugins": [ diff --git a/Source/Monolith/MonolithCharacter.cpp b/Source/Monolith/MonolithCharacter.cpp index 4dff0a4..2861ea2 100644 --- a/Source/Monolith/MonolithCharacter.cpp +++ b/Source/Monolith/MonolithCharacter.cpp @@ -1,9 +1,8 @@ // Copyright Epic Games, Inc. All Rights Reserved. #include "MonolithCharacter.h" -#include "MonolithProjectile.h" #include "Animation/AnimInstance.h" -#include "Camera/CameraComponent.h" +#include "PilotCamera.h" #include "Components/CapsuleComponent.h" #include "Components/SkeletalMeshComponent.h" #include "EnhancedInputComponent.h" @@ -22,7 +21,7 @@ AMonolithCharacter::AMonolithCharacter() GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f); // Create a CameraComponent - FirstPersonCameraComponent = CreateDefaultSubobject(TEXT("FirstPersonCamera")); + FirstPersonCameraComponent = CreateDefaultSubobject(TEXT("FirstPersonCamera")); FirstPersonCameraComponent->SetupAttachment(GetCapsuleComponent()); FirstPersonCameraComponent->SetRelativeLocation(FVector(-10.f, 0.f, 60.f)); // Position the camera FirstPersonCameraComponent->bUsePawnControlRotation = true; @@ -78,6 +77,7 @@ void AMonolithCharacter::Move(const FInputActionValue& Value) // add movement AddMovementInput(GetActorForwardVector(), MovementVector.Y); AddMovementInput(GetActorRightVector(), MovementVector.X); + UE_LOG(LogTemp, Warning, TEXT("X: %f, Y: %f"), (float)MovementVector.X, (float)MovementVector.Y); } } diff --git a/Source/Monolith/MonolithCharacter.h b/Source/Monolith/MonolithCharacter.h index 083896c..da1d870 100644 --- a/Source/Monolith/MonolithCharacter.h +++ b/Source/Monolith/MonolithCharacter.h @@ -9,7 +9,7 @@ class UInputComponent; class USkeletalMeshComponent; -class UCameraComponent; +class UPilotCamera; class UInputAction; class UInputMappingContext; struct FInputActionValue; @@ -27,7 +27,7 @@ class AMonolithCharacter : public ACharacter /** First person camera */ UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true")) - UCameraComponent* FirstPersonCameraComponent; + UPilotCamera* FirstPersonCameraComponent; /** Jump Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) @@ -36,6 +36,8 @@ class AMonolithCharacter : public ACharacter /** Move Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) UInputAction* MoveAction; + + int fortnite = 69; public: AMonolithCharacter(); @@ -64,8 +66,5 @@ protected: public: /** Returns Mesh1P subobject **/ USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; } - /** Returns FirstPersonCameraComponent subobject **/ - UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; } - }; diff --git a/Source/Monolith/MonolithProjectile.cpp b/Source/Monolith/MonolithProjectile.cpp deleted file mode 100644 index b6476e9..0000000 --- a/Source/Monolith/MonolithProjectile.cpp +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "MonolithProjectile.h" -#include "GameFramework/ProjectileMovementComponent.h" -#include "Components/SphereComponent.h" - -AMonolithProjectile::AMonolithProjectile() -{ - // Use a sphere as a simple collision representation - CollisionComp = CreateDefaultSubobject(TEXT("SphereComp")); - CollisionComp->InitSphereRadius(5.0f); - CollisionComp->BodyInstance.SetCollisionProfileName("Projectile"); - CollisionComp->OnComponentHit.AddDynamic(this, &AMonolithProjectile::OnHit); // set up a notification for when this component hits something blocking - - // Players can't walk on it - CollisionComp->SetWalkableSlopeOverride(FWalkableSlopeOverride(WalkableSlope_Unwalkable, 0.f)); - CollisionComp->CanCharacterStepUpOn = ECB_No; - - // Set as root component - RootComponent = CollisionComp; - - // Use a ProjectileMovementComponent to govern this projectile's movement - ProjectileMovement = CreateDefaultSubobject(TEXT("ProjectileComp")); - ProjectileMovement->UpdatedComponent = CollisionComp; - ProjectileMovement->InitialSpeed = 3000.f; - ProjectileMovement->MaxSpeed = 3000.f; - ProjectileMovement->bRotationFollowsVelocity = true; - ProjectileMovement->bShouldBounce = true; - - // Die after 3 seconds by default - InitialLifeSpan = 3.0f; -} - -void AMonolithProjectile::OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit) -{ - // Only add impulse and destroy projectile if we hit a physics - if ((OtherActor != nullptr) && (OtherActor != this) && (OtherComp != nullptr) && OtherComp->IsSimulatingPhysics()) - { - OtherComp->AddImpulseAtLocation(GetVelocity() * 100.0f, GetActorLocation()); - - Destroy(); - } -} \ No newline at end of file diff --git a/Source/Monolith/MonolithProjectile.h b/Source/Monolith/MonolithProjectile.h deleted file mode 100644 index df67be8..0000000 --- a/Source/Monolith/MonolithProjectile.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "CoreMinimal.h" -#include "GameFramework/Actor.h" -#include "MonolithProjectile.generated.h" - -class USphereComponent; -class UProjectileMovementComponent; - -UCLASS(config=Game) -class AMonolithProjectile : public AActor -{ - GENERATED_BODY() - - /** Sphere collision component */ - UPROPERTY(VisibleDefaultsOnly, Category=Projectile) - USphereComponent* CollisionComp; - - /** Projectile movement component */ - UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Movement, meta = (AllowPrivateAccess = "true")) - UProjectileMovementComponent* ProjectileMovement; - -public: - AMonolithProjectile(); - - /** called when projectile hits something */ - UFUNCTION() - void OnHit(UPrimitiveComponent* HitComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, FVector NormalImpulse, const FHitResult& Hit); - - /** Returns CollisionComp subobject **/ - USphereComponent* GetCollisionComp() const { return CollisionComp; } - /** Returns ProjectileMovement subobject **/ - UProjectileMovementComponent* GetProjectileMovement() const { return ProjectileMovement; } -}; - diff --git a/Source/Monolith/PilotCamera.cpp b/Source/Monolith/PilotCamera.cpp new file mode 100644 index 0000000..50b2375 --- /dev/null +++ b/Source/Monolith/PilotCamera.cpp @@ -0,0 +1,23 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "PilotCamera.h" +#include "MonolithPlayerController.h" +#include "MonolithCharacter.h" +#include "GameFramework/CharacterMovementComponent.h" + +void UPilotCamera::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + if (m_Movement == nullptr) + { + AMonolithCharacter* PlayerChar = Cast + ( + Cast(GetWorld()->GetFirstPlayerController())->GetPawn() + ); + if (PlayerChar == nullptr) return; + m_Movement = PlayerChar->GetComponentByClass(); + if (m_Movement == nullptr) return; + } + UE_LOG(LogTemp, Warning, TEXT("Acc: %f, Vel: %f"), m_Movement->GetCurrentAcceleration().X, m_Movement->Velocity.X); +} diff --git a/Source/Monolith/PilotCamera.h b/Source/Monolith/PilotCamera.h new file mode 100644 index 0000000..f50fb86 --- /dev/null +++ b/Source/Monolith/PilotCamera.h @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Camera/CameraComponent.h" +#include "PilotCamera.generated.h" + +class UCharacterMovementComponent; + +UCLASS() +class MONOLITH_API UPilotCamera : public UCameraComponent +{ + GENERATED_BODY() + +private: + void TickComponent(float DeltaTime + , ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction); + + UCharacterMovementComponent* m_Movement; +}; diff --git a/Source/Monolith/TP_PickUpComponent.cpp b/Source/Monolith/TP_PickUpComponent.cpp deleted file mode 100644 index 2042d3a..0000000 --- a/Source/Monolith/TP_PickUpComponent.cpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#include "TP_PickUpComponent.h" - -UTP_PickUpComponent::UTP_PickUpComponent() -{ - // Setup the Sphere Collision - SphereRadius = 32.f; -} - -void UTP_PickUpComponent::BeginPlay() -{ - Super::BeginPlay(); - - // Register our Overlap Event - OnComponentBeginOverlap.AddDynamic(this, &UTP_PickUpComponent::OnSphereBeginOverlap); -} - -void UTP_PickUpComponent::OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) -{ - // Checking if it is a First Person Character overlapping - AMonolithCharacter* Character = Cast(OtherActor); - if(Character != nullptr) - { - // Notify that the actor is being picked up - OnPickUp.Broadcast(Character); - - // Unregister from the Overlap Event so it is no longer triggered - OnComponentBeginOverlap.RemoveAll(this); - } -} diff --git a/Source/Monolith/TP_PickUpComponent.h b/Source/Monolith/TP_PickUpComponent.h deleted file mode 100644 index 110d5e2..0000000 --- a/Source/Monolith/TP_PickUpComponent.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "CoreMinimal.h" -#include "Components/SphereComponent.h" -#include "MonolithCharacter.h" -#include "TP_PickUpComponent.generated.h" - -// Declaration of the delegate that will be called when someone picks this up -// The character picking this up is the parameter sent with the notification -DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnPickUp, AMonolithCharacter*, PickUpCharacter); - -UCLASS(Blueprintable, BlueprintType, ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) -class MONOLITH_API UTP_PickUpComponent : public USphereComponent -{ - GENERATED_BODY() - -public: - - /** Delegate to whom anyone can subscribe to receive this event */ - UPROPERTY(BlueprintAssignable, Category = "Interaction") - FOnPickUp OnPickUp; - - UTP_PickUpComponent(); -protected: - - /** Called when the game starts */ - virtual void BeginPlay() override; - - /** Code for when something overlaps this component */ - UFUNCTION() - void OnSphereBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); -}; \ No newline at end of file diff --git a/Source/Monolith/TP_WeaponComponent.cpp b/Source/Monolith/TP_WeaponComponent.cpp deleted file mode 100644 index f0ecda8..0000000 --- a/Source/Monolith/TP_WeaponComponent.cpp +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - - -#include "TP_WeaponComponent.h" -#include "MonolithCharacter.h" -#include "MonolithProjectile.h" -#include "GameFramework/PlayerController.h" -#include "Camera/PlayerCameraManager.h" -#include "Kismet/GameplayStatics.h" -#include "EnhancedInputComponent.h" -#include "EnhancedInputSubsystems.h" -#include "Animation/AnimInstance.h" -#include "Engine/LocalPlayer.h" -#include "Engine/World.h" - -// Sets default values for this component's properties -UTP_WeaponComponent::UTP_WeaponComponent() -{ - // Default offset from the character location for projectiles to spawn - MuzzleOffset = FVector(100.0f, 0.0f, 10.0f); -} - - -void UTP_WeaponComponent::Fire() -{ - if (Character == nullptr || Character->GetController() == nullptr) - { - return; - } - - // Try and fire a projectile - if (ProjectileClass != nullptr) - { - UWorld* const World = GetWorld(); - if (World != nullptr) - { - APlayerController* PlayerController = Cast(Character->GetController()); - const FRotator SpawnRotation = PlayerController->PlayerCameraManager->GetCameraRotation(); - // MuzzleOffset is in camera space, so transform it to world space before offsetting from the character location to find the final muzzle position - const FVector SpawnLocation = GetOwner()->GetActorLocation() + SpawnRotation.RotateVector(MuzzleOffset); - - //Set Spawn Collision Handling Override - FActorSpawnParameters ActorSpawnParams; - ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding; - - // Spawn the projectile at the muzzle - World->SpawnActor(ProjectileClass, SpawnLocation, SpawnRotation, ActorSpawnParams); - } - } - - // Try and play the sound if specified - if (FireSound != nullptr) - { - UGameplayStatics::PlaySoundAtLocation(this, FireSound, Character->GetActorLocation()); - } - - // Try and play a firing animation if specified - if (FireAnimation != nullptr) - { - // Get the animation object for the arms mesh - UAnimInstance* AnimInstance = Character->GetMesh1P()->GetAnimInstance(); - if (AnimInstance != nullptr) - { - AnimInstance->Montage_Play(FireAnimation, 1.f); - } - } -} - -bool UTP_WeaponComponent::AttachWeapon(AMonolithCharacter* TargetCharacter) -{ - Character = TargetCharacter; - - // Check that the character is valid, and has no weapon component yet - if (Character == nullptr || Character->GetInstanceComponents().FindItemByClass()) - { - return false; - } - - // Attach the weapon to the First Person Character - FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); - AttachToComponent(Character->GetMesh1P(), AttachmentRules, FName(TEXT("GripPoint"))); - - // add the weapon as an instance component to the character - Character->AddInstanceComponent(this); - - // Set up action bindings - if (APlayerController* PlayerController = Cast(Character->GetController())) - { - if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer())) - { - // Set the priority of the mapping to 1, so that it overrides the Jump action with the Fire action when using touch input - Subsystem->AddMappingContext(FireMappingContext, 1); - } - - if (UEnhancedInputComponent* EnhancedInputComponent = Cast(PlayerController->InputComponent)) - { - // Fire - EnhancedInputComponent->BindAction(FireAction, ETriggerEvent::Triggered, this, &UTP_WeaponComponent::Fire); - } - } - - return true; -} - -void UTP_WeaponComponent::EndPlay(const EEndPlayReason::Type EndPlayReason) -{ - if (Character == nullptr) - { - return; - } - - if (APlayerController* PlayerController = Cast(Character->GetController())) - { - if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController->GetLocalPlayer())) - { - Subsystem->RemoveMappingContext(FireMappingContext); - } - } -} \ No newline at end of file diff --git a/Source/Monolith/TP_WeaponComponent.h b/Source/Monolith/TP_WeaponComponent.h deleted file mode 100644 index e09e5ae..0000000 --- a/Source/Monolith/TP_WeaponComponent.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright Epic Games, Inc. All Rights Reserved. - -#pragma once - -#include "CoreMinimal.h" -#include "Components/SkeletalMeshComponent.h" -#include "TP_WeaponComponent.generated.h" - -class AMonolithCharacter; - -UCLASS(Blueprintable, BlueprintType, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent) ) -class MONOLITH_API UTP_WeaponComponent : public USkeletalMeshComponent -{ - GENERATED_BODY() - -public: - /** Projectile class to spawn */ - UPROPERTY(EditDefaultsOnly, Category=Projectile) - TSubclassOf ProjectileClass; - - /** Sound to play each time we fire */ - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Gameplay) - USoundBase* FireSound; - - /** AnimMontage to play each time we fire */ - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Gameplay) - UAnimMontage* FireAnimation; - - /** Gun muzzle's offset from the characters location */ - UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Gameplay) - FVector MuzzleOffset; - - /** MappingContext */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputMappingContext* FireMappingContext; - - /** Fire Input Action */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputAction* FireAction; - - /** Sets default values for this component's properties */ - UTP_WeaponComponent(); - - /** Attaches the actor to a FirstPersonCharacter */ - UFUNCTION(BlueprintCallable, Category="Weapon") - bool AttachWeapon(AMonolithCharacter* TargetCharacter); - - /** Make the weapon Fire a Projectile */ - UFUNCTION(BlueprintCallable, Category="Weapon") - void Fire(); - -protected: - /** Ends gameplay for this component. */ - UFUNCTION() - virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override; - -private: - /** The Character holding this weapon*/ - AMonolithCharacter* Character; -};