Added a Directional Arrow to Mini Waypoints

This commit is contained in:
Rafal Swierczek 2023-11-26 23:26:01 +00:00
parent cbf89a2c93
commit c51f2ab7b6
6 changed files with 22 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:c4ea69a798330d981b7d72fce4e0999e306589ee7e0b3b49ce9a69adf36d6348 oid sha256:d3943e1a064276d17b897a7a10a3c42a35c75d6c02117bd1ea962544f3576a9b
size 654898 size 654898

View File

@ -4,7 +4,6 @@
#include "MiniWaypoint.h" #include "MiniWaypoint.h"
void UMiniWaypoint::NativeTick(const FGeometry& MyGeometry, float InDeltaTime) void UMiniWaypoint::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
{ {
Super::NativeTick(MyGeometry, InDeltaTime); Super::NativeTick(MyGeometry, InDeltaTime);
@ -14,13 +13,15 @@ void UMiniWaypoint::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
FVector2D ScreenLoc; FVector2D ScreenLoc;
PlayerController->ProjectWorldLocationToScreen(WorldLoc, ScreenLoc); PlayerController->ProjectWorldLocationToScreen(WorldLoc, ScreenLoc);
float TargetYaw = (WorldLoc - PlayerController->GetPawn()->GetActorLocation()).Rotation().Yaw;
float PlayerYaw = PlayerController->GetControlRotation().Yaw;
if (TargetYaw < 0 ) TargetYaw += 360;
ArrowImage->SetRenderTransformAngle(TargetYaw - PlayerYaw);
// Check if waypoint is outside of players vision frustum // Check if waypoint is outside of players vision frustum
if (FMath::IsWithin(ScreenLoc.X, -0.01, 0.01) && FMath::IsWithin(ScreenLoc.Y, -0.01, 0.01)) if (FMath::IsWithin(ScreenLoc.X, -0.01, 0.01) && FMath::IsWithin(ScreenLoc.Y, -0.01, 0.01))
{ {
float PlayerYaw = PlayerController->GetControlRotation().Yaw;
float TargetYaw = (WorldLoc - PlayerController->GetPawn()->GetActorLocation()).Rotation().Yaw;
if (TargetYaw < 0 ) TargetYaw += 360;
// Check if waypoint is closer to the players right // Check if waypoint is closer to the players right
bool TargetOnTheRight; bool TargetOnTheRight;
if (PlayerYaw >= TargetYaw) if (PlayerYaw >= TargetYaw)
@ -57,7 +58,8 @@ void UMiniWaypoint::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
IconCanvasPanelSlot->SetPosition(ScreenLoc); IconCanvasPanelSlot->SetPosition(ScreenLoc);
} }
void UMiniWaypoint::SetIconPanelSlot(UImage* IconImage) void UMiniWaypoint::SetIconPanelSlot(UCanvasPanel* IconParent, UImage* ArrowImageComp)
{ {
IconCanvasPanelSlot = Cast<UCanvasPanelSlot>(IconImage->Slot); ArrowImage = ArrowImageComp;
IconCanvasPanelSlot = Cast<UCanvasPanelSlot>(IconParent->Slot);
} }

View File

@ -5,6 +5,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include "Components/CanvasPanelSlot.h" #include "Components/CanvasPanelSlot.h"
#include "Components/CanvasPanel.h"
#include "Components/Image.h" #include "Components/Image.h"
#include "MiniWaypoint.generated.h" #include "MiniWaypoint.generated.h"
@ -19,10 +20,11 @@ class ENDLESSVENDETTA_API UMiniWaypoint : public UUserWidget
void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override; void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override;
UCanvasPanelSlot* IconCanvasPanelSlot; UCanvasPanelSlot* IconCanvasPanelSlot;
UImage* ArrowImage;
protected: protected:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void SetIconPanelSlot(UImage* IconImage); void SetIconPanelSlot(UCanvasPanel* IconParent, UImage* ArrowImageComp);
public: public:
FVector WorldLoc = FVector(0, 0, 0); FVector WorldLoc = FVector(0, 0, 0);