Implement an interact hold input action and a new callback for it, seed bed collect seed action as well, change lavender seed mesh to sprite

This commit is contained in:
2026-10-01 22:01:54 +02:00
parent b5304a74aa
commit f2115c537b
10 changed files with 302 additions and 9 deletions

View File

@@ -84,14 +84,24 @@ AActor* UInteractionSubsystem::GetClosestInteractable(const UObject* WorldContex
if (!Actor.IsValid())
continue;
const float Dist = FVector::DistSquared(Actor->GetActorLocation(), PlayerCharacter->GetActorLocation());
// Actors whose real interaction target is not their own origin (a bloomed plant inside a seed bed
// grid, for example) report the point everything should be measured against. Distance, the on-screen
// test and the "closest wins" pick then all reason about that point instead of the actor's center.
// Zero means the actor has no preference, so its own origin is used.
FVector FocusLocation = IInteractableActorInterface::Execute_GetInteractionFocusLocation(Actor.Get());
if (FocusLocation.IsZero())
{
FocusLocation = Actor->GetActorLocation();
}
const float Dist = FVector::DistSquared(FocusLocation, PlayerCharacter->GetActorLocation());
const float MaxInteractionDistance = IInteractableActorInterface::Execute_GetInteractionDistance(Actor.Get());
if (FMath::Pow(MaxInteractionDistance, 2) < Dist || Dist > ClosestDist)
continue;
FVector2D ScreenLoc;
if (!PC->ProjectWorldLocationToScreen(Actor->GetActorLocation(), ScreenLoc))
if (!PC->ProjectWorldLocationToScreen(FocusLocation, ScreenLoc))
{
continue;
}

View File

@@ -3,6 +3,7 @@
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "UObject/Interface.h"
#include "InteractionSettings.h"
#include "InteractableActorInterface.generated.h"
@@ -44,4 +45,18 @@ public:
{
return GetDefault<UInteractionSettings>()->InteractableMaxDistance;
}
/**
* Point the interaction system should reason about for this actor: the distance check, the on-screen
* test and the "closest wins" pick all measure towards it. Zero means "no preference" and the actor's
* own origin is used, which is right for a single-object actor. An actor whose real interaction target
* sits somewhere else (a bloomed plant inside a seed bed grid, for example) overrides this so the prompt
* lands where the player looks.
*/
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "Interactable")
FVector GetInteractionFocusLocation() const;
virtual FVector GetInteractionFocusLocation_Implementation() const
{
return FVector::ZeroVector;
}
};