From 8ef1ecf488068bb956a285e7365b84472c08fe18 Mon Sep 17 00:00:00 2001 From: PHILIP WHITE Date: Sat, 7 Oct 2023 00:30:37 +0100 Subject: [PATCH] Updated PlayerCharacter to Crouch --- .../Blueprints/BP_FirstPersonCharacter.uasset | 4 +- .../Input/Actions/IA_Crouch.uasset | 3 + .../FirstPerson/Input/IMC_Default.uasset | 4 +- .../VisionLink/Ping/PingImage.uasset | 4 +- .../EndlessVendettaCharacter.cpp | 90 +++++++++++-------- .../EndlessVendettaCharacter.h | 47 +++++----- 6 files changed, 87 insertions(+), 65 deletions(-) create mode 100644 EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Crouch.uasset diff --git a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset index 68a7823a..c68329b2 100644 --- a/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset +++ b/EndlessVendetta/Content/FirstPerson/Blueprints/BP_FirstPersonCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:072d87c768407249e6e50f7b87ab9a88392c17cf82c72934e3c947e2943210bb -size 26284 +oid sha256:dfda56ad26d2c6bcc0fec5a9baf228eeba7cf6c4728566886d051ea933c3e3f2 +size 26540 diff --git a/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Crouch.uasset b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Crouch.uasset new file mode 100644 index 00000000..9572838e --- /dev/null +++ b/EndlessVendetta/Content/FirstPerson/Input/Actions/IA_Crouch.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:89e10b0349f4813e2c47bd905ee012e34d04b54d8e793ab70c6f813652b06cc9 +size 1360 diff --git a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset index 55abcd6c..aea937a7 100644 --- a/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset +++ b/EndlessVendetta/Content/FirstPerson/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3af06cb5478091fcf55d1069e28395f32708276bd53cc5dce82faa2a2d1f822b -size 16317 +oid sha256:16c8e5300c4e8a4ec385de79af752132edd42ddda7a67010daca5a560dc82ac4 +size 16903 diff --git a/EndlessVendetta/Content/Gadgets/ReconGadgets/VisionLink/Ping/PingImage.uasset b/EndlessVendetta/Content/Gadgets/ReconGadgets/VisionLink/Ping/PingImage.uasset index 9f97a970..60b1fbff 100644 --- a/EndlessVendetta/Content/Gadgets/ReconGadgets/VisionLink/Ping/PingImage.uasset +++ b/EndlessVendetta/Content/Gadgets/ReconGadgets/VisionLink/Ping/PingImage.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d64b09bc01c01afde43af7565f5c136c6dff1330b0db17d871964513366fc5ad -size 74632 +oid sha256:71d15ce6872f9185621eabe6eb24774f8014dfddbc4e89e6c6961f662d269445 +size 74727 diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp index 448d805c..2c982762 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.cpp @@ -6,6 +6,7 @@ #include "Components/CapsuleComponent.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" +#include "GameFramework/CharacterMovementComponent.h" ////////////////////////////////////////////////////////////////////////// @@ -16,6 +17,8 @@ AEndlessVendettaCharacter::AEndlessVendettaCharacter() // Character doesnt have a rifle at start bHasRifle = false; + //Enable Crouching + GetCharacterMovement()->GetNavAgentPropertiesRef().bCanCrouch = true; // Set size for collision capsule GetCapsuleComponent()->InitCapsuleSize(55.f, 96.0f); @@ -33,7 +36,6 @@ AEndlessVendettaCharacter::AEndlessVendettaCharacter() Mesh1P->CastShadow = false; //Mesh1P->SetRelativeRotation(FRotator(0.9f, -19.19f, 5.2f)); Mesh1P->SetRelativeLocation(FVector(-30.f, 0.f, -150.f)); - } void AEndlessVendettaCharacter::BeginPlay() @@ -59,7 +61,6 @@ void AEndlessVendettaCharacter::BeginPlay() GadgetManager->SpawnGadgets(Cast(PlayersCamera)); break; } - } //////////////////////////////////////////////////////////////////////////// Input @@ -82,16 +83,32 @@ void AEndlessVendettaCharacter::SetupPlayerInputComponent(class UInputComponent* // Gadget Toggling EnhancedInputComponent->BindAction(ReconAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::ToggleRecon); EnhancedInputComponent->BindAction(CombatAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::ToggleCombat); - + //Weapon Switching EnhancedInputComponent->BindAction(EquipPrimaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipPrimary); EnhancedInputComponent->BindAction(EquipSecondaryWeapon, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::EquipSecondary); //Weapon Shooting EnhancedInputComponent->BindAction(TapShootAction, ETriggerEvent::Triggered, this, &AEndlessVendettaCharacter::TapFireCaller); + + //Crouching + EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Started, this, &AEndlessVendettaCharacter::SetCrouch); + EnhancedInputComponent->BindAction(CrouchAction, ETriggerEvent::Completed, this, &AEndlessVendettaCharacter::SetUnCrouch); } } +void AEndlessVendettaCharacter::SetCrouch() +{ + Crouch(); + GLog->Log("Crouching"); +} + +void AEndlessVendettaCharacter::SetUnCrouch() +{ + UnCrouch(); + GLog->Log("UnCrouching"); +} + void AEndlessVendettaCharacter::ToggleRecon() { if (IsValid(PrimaryWeapon)) EquipPrimary(); @@ -145,11 +162,11 @@ void AEndlessVendettaCharacter::EquipPrimary() } if (IsValid(SecondaryWeapon)) EquipSecondary(); - + // Marcel I respect you, like you and what not, please for the love of god don't touch these two guard clauses ///////////////////////////////////////////////////////////////////////////////////////////////////////////// - if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;///////////////////////// - if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;/////////////////////// + if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return; ///////////////////////// + if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return; /////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////// FActorSpawnParameters spawnParams; @@ -163,28 +180,28 @@ void AEndlessVendettaCharacter::EquipPrimary() //Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object //We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor PrimaryWeapon = Cast(PrimaryWeaponActor); - + //If primary weapon is not there but secondary weapon is it will call equipSecondary. //EquipSecondary checks and sees that secondary is there so it will call to destroy itself //Code goes back and sees primary weapon is not there anymore and spawns it in. //Same thing for the EquipSecondary() - + // if (!IsValid(PrimaryWeapon)) // { // if (IsValid(SecondaryWeapon)) EquipSecondary(); // // UE_LOG(LogTemp, Display, TEXT("Primary equipped")); - // bHasRifle = true; - // FActorSpawnParameters spawnParams; - // spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - // FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); - // //Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass - // AActor* PrimaryWeaponActor = GetWorld()->SpawnActor(PrimaryWeaponClass, spawnParams); - // PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); - // //Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object - // //We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor - // PrimaryWeapon = Cast(PrimaryWeaponActor); + // bHasRifle = true; + // FActorSpawnParameters spawnParams; + // spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + // FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); + // //Creating a new actor object called PrimaryWeapon that is based off primaryweaponClass + // AActor* PrimaryWeaponActor = GetWorld()->SpawnActor(PrimaryWeaponClass, spawnParams); + // PrimaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); + // //Changing PrimaryWeaponActor to ABaseWeaponClass type instead of actor and storing it into PrimaryWeapon which is a ABaseClass Object + // //We do this because we need to check if PrimaryWeapon is equipped and we want primaryweapon to be ABaseWeapon type and not a generic AActor + // PrimaryWeapon = Cast(PrimaryWeaponActor); // // } // else if (IsValid(PrimaryWeapon)) @@ -197,49 +214,48 @@ void AEndlessVendettaCharacter::EquipPrimary() void AEndlessVendettaCharacter::EquipSecondary() { if (IsValid(SecondaryWeapon)) - { - SecondaryWeapon->Destroy(); + { + SecondaryWeapon->Destroy(); SecondaryWeapon = nullptr; - bHasRifle = false; - return; - } + bHasRifle = false; + return; + } if (IsValid(PrimaryWeapon)) EquipPrimary(); - + // Marcel I respect you, like you and what not, please for the love of god don't touch these two guard clauses ///////////////////////////////////////////////////////////////////////////////////////////////////////////// - if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return;///////////////////////// - if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return;/////////////////////// + if (GadgetManager->IsReconEquipped() && !GadgetManager->TryToUnequipRecon()) return; ///////////////////////// + if (GadgetManager->IsCombatEquipped() && !GadgetManager->TryToUnequipCombat()) return; /////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////////////// FActorSpawnParameters spawnParams; spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); - + bHasRifle = true; AActor* SecondaryWeaponActor = GetWorld()->SpawnActor(SecondaryWeaponClass, spawnParams); SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); SecondaryWeapon = Cast(SecondaryWeaponActor); - + // if (!IsValid(SecondaryWeapon)) // { // if (IsValid(PrimaryWeapon)) EquipPrimary(); // // UE_LOG(LogTemp, Display, TEXT("Secondary equipped")); - // bHasRifle = true; - // FActorSpawnParameters spawnParams; - // spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; - // FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); - // AActor* SecondaryWeaponActor = GetWorld()->SpawnActor(SecondaryWeaponClass, spawnParams); - // SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); - // SecondaryWeapon = Cast(SecondaryWeaponActor); + // bHasRifle = true; + // FActorSpawnParameters spawnParams; + // spawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn; + // FAttachmentTransformRules AttachmentRules(EAttachmentRule::SnapToTarget, true); + // AActor* SecondaryWeaponActor = GetWorld()->SpawnActor(SecondaryWeaponClass, spawnParams); + // SecondaryWeaponActor->AttachToComponent(Mesh1P, AttachmentRules, FName("GripPoint")); + // SecondaryWeapon = Cast(SecondaryWeaponActor); // } // else if (IsValid(SecondaryWeapon)) // { // SecondaryWeapon->Destroy(); // bHasRifle = false; // } - } //Calls the fire function in the baseWeaponClass @@ -325,4 +341,4 @@ void AEndlessVendettaCharacter::SetHasRifle(bool bNewHasRifle) bool AEndlessVendettaCharacter::GetHasRifle() { return bHasRifle; -} \ No newline at end of file +} diff --git a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h index cf41bef6..00f93ad3 100644 --- a/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h +++ b/EndlessVendetta/Source/EndlessVendetta/EndlessVendettaCharacter.h @@ -33,35 +33,38 @@ class AEndlessVendettaCharacter : public ACharacter /** MappingContext */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputMappingContext* DefaultMappingContext; + UInputMappingContext* DefaultMappingContext; /** Jump Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputAction* JumpAction; + UInputAction* JumpAction; /** Move Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputAction* MoveAction; + UInputAction* MoveAction; // Gadget Actions UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) UInputAction* ReconAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) UInputAction* CombatAction; - + /** Weapon Equip Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputAction* EquipPrimaryWeapon; + UInputAction* EquipPrimaryWeapon; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputAction* EquipSecondaryWeapon; + UInputAction* EquipSecondaryWeapon; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputAction* TapShootAction; + UInputAction* TapShootAction; UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Input, meta=(AllowPrivateAccess = "true")) - class UInputAction* HoldShootAction; - + UInputAction* HoldShootAction; + + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = ( AllowPrivateAccess = "true" )) + UInputAction* CrouchAction; + public: AEndlessVendettaCharacter(); @@ -73,7 +76,6 @@ protected: AGadgetManager* GadgetManager; public: - /** Look Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) class UInputAction* LookAction; @@ -103,7 +105,6 @@ public: UFUNCTION(BlueprintCallable, Category = "Weapons") void TapFireCaller(); - protected: /** Called for movement input */ void Move(const FInputActionValue& Value); @@ -114,25 +115,27 @@ protected: void ToggleRecon(); void ToggleCombat(); - + void EquipPrimary(); - + void EquipSecondary(); //Called from Player BluePrints //UFUNCTION(BlueprintCallable, Category = "Weapons") //void WeaponPickUpSystem(AActor* PickedUpWeapon); - -protected: + // APawn interface virtual void SetupPlayerInputComponent(UInputComponent* InputComponent) override; // End of APawn interface -public: - /** Returns Mesh1P subobject **/ - USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; } - /** Returns FirstPersonCameraComponent subobject **/ - UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; } - -}; + UFUNCTION(BlueprintCallable, Category = "Stealth") + void SetCrouch(); + UFUNCTION(BlueprintCallable, Category = "Stealth") + void SetUnCrouch(); +public: + /** Returns Mesh1P Sub-object **/ + USkeletalMeshComponent* GetMesh1P() const { return Mesh1P; } + /** Returns FirstPersonCameraComponent Sub-object **/ + UCameraComponent* GetFirstPersonCameraComponent() const { return FirstPersonCameraComponent; } +};