implemented pick up item

This commit is contained in:
Ji Yoon Rhee 2024-06-17 23:38:43 +09:00
parent 959723df6a
commit 7c5833f033
30 changed files with 74 additions and 76 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -18,7 +18,7 @@ void AHYInteractableActor::Interact_Implementation(APlayerController* Controller
FString AHYInteractableActor::GetInteractText() const FString AHYInteractableActor::GetInteractText() const
{ {
return FString::Printf(TEXT("s%: Press F to %s"), *Name, *Action); return FString::Printf(TEXT("%s: Press F to %s"), *Name, *Action);
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned

View File

@ -30,7 +30,7 @@ public:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
FString Action; FString Action;
UFUNCTION(Blueprintcallable, Category = "Pickup") UFUNCTION(BlueprintCallable, Category = "Pickup")
FString GetInteractText() const; FString GetInteractText() const;
protected: protected:

View File

@ -12,7 +12,7 @@ AHYManualPickUp::AHYManualPickUp()
ItemID = FName("No ID"); ItemID = FName("No ID");
Super::Name = "Item"; Super::Name = "Item";
Super::Action = "pickup"; Super::Action = "Pick up";
} }
void AHYManualPickUp::Interact_Implementation(APlayerController* Controller) void AHYManualPickUp::Interact_Implementation(APlayerController* Controller)

View File

@ -31,7 +31,7 @@ public:
UFUNCTION(BlueprintCallable, Category = "Utils") UFUNCTION(BlueprintCallable, Category = "Utils")
bool AddItemToInventoryByID(FName ID); bool AddItemToInventoryByID(FName ID);
UPROPERTY(VisibleAnywhere, BlueprintReadWrite) UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
class AHYInteractableActor* CurrentInteractable; class AHYInteractableActor* CurrentInteractable;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite) UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
@ -43,14 +43,15 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
int32 InventoryWeightLimit; int32 InventoryWeightLimit;
//interacts with the Interactable objects
UFUNCTION(BlueprintCallable, Category = "Utils")
void Interact();
#pragma endregion #pragma endregion
protected: protected:
//interacts with the Interactable objects
void Interact();
//abstract function to override in order to //abstract function to override in order to
//bind actions or axis to different input components //bind actions or axis to different input components
virtual void SetupInputComponent() override; virtual void SetupInputComponent() override;

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "GameFramework/Actor.h" #include "GameFramework/Actor.h"
#include "Engine/DataTable.h" #include "Engine/DataTable.h"
#include "HYManualPickUp.h"
#include "InventoryItem.generated.h" #include "InventoryItem.generated.h"
/** /**
@ -22,6 +23,9 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
FName ItemID; FName ItemID;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<class AHYManualPickUp> ItemPickup;
//name of the item //name of the item
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
FText ItemName; FText ItemName;

View File

@ -2,19 +2,10 @@
#pragma once #pragma once
#ifndef _HWANYOUNG2_H__
#define _HWANYOUNG2_H__
#include "CoreMinimal.h" #include "CoreMinimal.h"
UENUM(BlueprintType) #define COLLISION_INTERACTABLE ECC_GameTraceChannel1;
enum class EAbilityInputID : uint8
{ #endif
None UMETA(DisplayName = "None"), //no input given
Confirm UMETA(DisplayName = "Confirm"),
Cancel UMETA(DisplayName = "Cancel"),
UseWeapon UMETA(DisplayName = "Use Weapon"), //using melee weapon to attack
SwitchWeapon UMETA(DisplayName = "Switch Weapons"), //switching weapons
UseActive1 UMETA(DisplayName = "Use Active Skill 1"), //active 1
UseActive2 UMETA(DisplayName = "Use Active Skill 2"), //active 2
UseActive3 UMETA(DisplayName = "Use Active Skill 3"), //active 3
UseUlt UMETA(DisplayName = "Use Ultimate Skill"), //ult
PassiveDash UMETA(DisplayName = "Dash") //dash (passive)
};

View File

@ -63,7 +63,7 @@ void Ahwanyoung2Character::CheckForInteractables()
FHitResult HitResult; FHitResult HitResult;
// The range of area the system should check for interactables // The range of area the system should check for interactables
int32 Range = 500; //this can be changed int32 Range = 800; //this can be changed
//The start of the trace is the transform of the follow camera //The start of the trace is the transform of the follow camera
FVector StartTrace = FollowCamera->GetComponentLocation(); FVector StartTrace = FollowCamera->GetComponentLocation();
@ -80,22 +80,21 @@ void Ahwanyoung2Character::CheckForInteractables()
//object attached to the character and cast it as player character controller class //object attached to the character and cast it as player character controller class
AHYPlayerCharacController* IController = Cast<AHYPlayerCharacController>(GetController()); AHYPlayerCharacController* IController = Cast<AHYPlayerCharacController>(GetController());
if (IController) {
//Checking if something is hit by the line cast within the range //Checking if something is hit by the line cast within the range
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartTrace, EndTrace, if (GetWorld()->LineTraceSingleByChannel(HitResult, StartTrace, EndTrace,
ECC_Visibility, QueryParams)) { ECC_Visibility, QueryParams)) {
//Cast the actor to AInteractable //Cast the actor to AInteractable
AHYInteractableActor* Interactable = Cast<AHYInteractableActor>(HitResult.GetActor()); if (AHYInteractableActor* Interactable = Cast<AHYInteractableActor>(HitResult.GetActor())) {
if (Interactable) {
IController->CurrentInteractable = Interactable; IController->CurrentInteractable = Interactable;
return; return;
} }
} } else {
IController->CurrentInteractable = nullptr; IController->CurrentInteractable = nullptr;
} }
} }