Started working on grab range

Signed-off-by: TjgL <lithmoneo@gmail.com>
This commit is contained in:
TjgL 2025-03-21 12:52:36 +01:00
parent 13c0dbe486
commit a7f9137dd5
4 changed files with 111 additions and 0 deletions

BIN
Content/Legumix/Player/BP_GrabComponent.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Legumix/Player/C_GrabMovement.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -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<ALMPlayer>(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<ALMItemDrop>(OtherActor))
{
OnDropOverlapped(ItemDrop);
}
}

View File

@ -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<ALMItemDrop*> 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<UCurveFloat> SpeedAtPosition;
TObjectPtr<ALMPlayer> 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);
};