Ok, I got it.
What I did:
- Wrote a new c++ function at my GameMode class that tells me if a actor location is inside my selection box.
MyGameMode.h
#pragma once
#include "GameFramework/GameMode.h"
#include "Core.h"
#include "math.h"
#include "MainGameMode.generated.h"
/**
*
*/
UCLASS()
class AMainGameMode : public AGameMode
{
GENERATED_UCLASS_BODY()
public:
UFUNCTION(BlueprintCallable, Category = "Utilities")
bool is2DVectorInRectangle(FVector2D Point, FVector2D RectangleStart, FVector2D RectangleEnd);
};
MyGameMode.cpp
#include "projectName.h"
#include "MainGameMode.h"
AMainGameMode::AMainGameMode(const class FPostConstructInitializeProperties& PCIP) : Super(PCIP)
{
}
bool AMainGameMode::is2DVectorInRectangle(FVector2D Point, FVector2D RectangleStart, FVector2D RectangleEnd) {
FVector2D min;
FVector2D max;
min.X = fminf(RectangleStart.X, RectangleEnd.X);
min.Y = fminf(RectangleStart.Y, RectangleEnd.Y);
max.X = fmaxf(RectangleStart.X, RectangleEnd.X);
max.Y = fmaxf(RectangleStart.Y, RectangleEnd.Y);
if (Point.X > min.X && Point.X < max.X) {
if (Point.Y > min.Y && Point.Y < max.Y) {
return true;
}
}
return false;
}
- Create this blueprint:
In your HUD blueprint graph:
3 additional methods to your HUD blueprint:
In your controller blueprint graph:
Input settings:
And that’s how it looks like then: