From a7f9137dd56fe90406ac648fd7f0549d22e6bae8 Mon Sep 17 00:00:00 2001 From: TjgL Date: Fri, 21 Mar 2025 12:52:36 +0100 Subject: [PATCH] Started working on grab range Signed-off-by: TjgL --- .../Legumix/Player/BP_GrabComponent.uasset | 3 ++ Content/Legumix/Player/C_GrabMovement.uasset | 3 ++ .../LegumeMix/Private/Player/LMGrabRange.cpp | 53 +++++++++++++++++++ Source/LegumeMix/Private/Player/LMGrabRange.h | 52 ++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 Content/Legumix/Player/BP_GrabComponent.uasset create mode 100644 Content/Legumix/Player/C_GrabMovement.uasset create mode 100644 Source/LegumeMix/Private/Player/LMGrabRange.cpp create mode 100644 Source/LegumeMix/Private/Player/LMGrabRange.h diff --git a/Content/Legumix/Player/BP_GrabComponent.uasset b/Content/Legumix/Player/BP_GrabComponent.uasset new file mode 100644 index 0000000..3f28caf --- /dev/null +++ b/Content/Legumix/Player/BP_GrabComponent.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94d44c354900a897e9d28ac01a7718cc6287fdbab0adc3c8916a0285692a56d9 +size 79004 diff --git a/Content/Legumix/Player/C_GrabMovement.uasset b/Content/Legumix/Player/C_GrabMovement.uasset new file mode 100644 index 0000000..31268a5 --- /dev/null +++ b/Content/Legumix/Player/C_GrabMovement.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8496ddd779404f4331461e71ede1cf9a4cd96bee35fe3d437fc8d8fb388f37a0 +size 5060 diff --git a/Source/LegumeMix/Private/Player/LMGrabRange.cpp b/Source/LegumeMix/Private/Player/LMGrabRange.cpp new file mode 100644 index 0000000..8dcea6c --- /dev/null +++ b/Source/LegumeMix/Private/Player/LMGrabRange.cpp @@ -0,0 +1,53 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "LMGrabRange.h" + +#include "LMItemDrop.h" +#include "Player/LMPlayer.h" + + +ULMGrabRange::ULMGrabRange() +{ + PrimaryComponentTick.bCanEverTick = true; + +} + +void ULMGrabRange::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) +{ + Super::TickComponent(DeltaTime, TickType, ThisTickFunction); + + +} + +void ULMGrabRange::OnDropOverlapped_Implementation(ALMItemDrop* ItemDrop) +{ + Drops.AddUnique(ItemDrop); +} + + +void ULMGrabRange::ConsumeDrop(ALMItemDrop* ItemDrop) +{ + ItemDrop->ConsumePack(Player); + +} + +void ULMGrabRange::BeginPlay() +{ + Super::BeginPlay(); + Player = CastChecked(GetOwner()); + OnComponentBeginOverlap.AddUniqueDynamic(this, &ULMGrabRange::OnComponentOverlap); +} + +void ULMGrabRange::OnComponentOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, + UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult) +{ + if (!bIsEnabled) + return; + + if (ALMItemDrop* ItemDrop = Cast(OtherActor)) + { + OnDropOverlapped(ItemDrop); + } +} + diff --git a/Source/LegumeMix/Private/Player/LMGrabRange.h b/Source/LegumeMix/Private/Player/LMGrabRange.h new file mode 100644 index 0000000..a8237aa --- /dev/null +++ b/Source/LegumeMix/Private/Player/LMGrabRange.h @@ -0,0 +1,52 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/SphereComponent.h" +#include "LMGrabRange.generated.h" + + +class ALMPlayer; +class ALMItemDrop; + +UCLASS(Blueprintable, ClassGroup=(Custom), meta=(BlueprintSpawnableComponent)) +class LEGUMEMIX_API ULMGrabRange : public USphereComponent +{ + GENERATED_BODY() + +private: + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Legumix, meta=(AllowPrivateAccess=true)) + bool bIsEnabled = true; + + UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category=Legumix, meta=(AllowPrivateAccess=true)) + TArray Drops; + + /** The range at which the drop is consumed. */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true, ClampMin=0.1f)) + float RangeToGrab = 10.f; + + /** Distance curve from 0-1 to the player. */ + UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=Legumix, meta=(AllowPrivateAccess=true)) + TObjectPtr SpeedAtPosition; + + TObjectPtr Player; + +public: + ULMGrabRange(); + UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category=Legumix) + void OnDropOverlapped(ALMItemDrop* ItemDrop); + + UFUNCTION(BlueprintCallable, Category=Legumix) + void ConsumeDrop(ALMItemDrop* ItemDrop); + + void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) override; + +protected: + virtual void BeginPlay() override; + +private: + UFUNCTION() + void OnComponentOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, + int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); +};