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
{
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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,19 +2,10 @@
#pragma once
#ifndef _HWANYOUNG2_H__
#define _HWANYOUNG2_H__
#include "CoreMinimal.h"
UENUM(BlueprintType)
enum class EAbilityInputID : uint8
{
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)
};
#define COLLISION_INTERACTABLE ECC_GameTraceChannel1;
#endif

View File

@ -63,7 +63,7 @@ void Ahwanyoung2Character::CheckForInteractables()
FHitResult HitResult;
// 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
FVector StartTrace = FollowCamera->GetComponentLocation();
@ -80,22 +80,21 @@ void Ahwanyoung2Character::CheckForInteractables()
//object attached to the character and cast it as player character controller class
AHYPlayerCharacController* IController = Cast<AHYPlayerCharacController>(GetController());
if (IController) {
//Checking if something is hit by the line cast within the range
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartTrace, EndTrace,
ECC_Visibility, QueryParams)) {
//Cast the actor to AInteractable
AHYInteractableActor* Interactable = Cast<AHYInteractableActor>(HitResult.GetActor());
if (Interactable) {
if (AHYInteractableActor* Interactable = Cast<AHYInteractableActor>(HitResult.GetActor())) {
IController->CurrentInteractable = Interactable;
return;
}
}
} else {
IController->CurrentInteractable = nullptr;
}
}