x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Box selection of actors

I'm planing to create a small game where the player can select created units (actors) on the map through the cursor/finger. Actually exactly like in games like Age of Empire etc.

What I currently have is only the visual "box" in the user interface. I have no idea at the moment how I can now select all actors that are within this box. Any ideas?

Blueprint Selection

A function like 'Vector Between (actorVector, vector2, vector2` on a 2D map would already help a lot.

Product Version: Not Selected
Tags:
more ▼

asked Mar 30 '14 at 09:20 PM in Blueprint Scripting

avatar image

marcjs
31 2 2 79

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

Ok, I got it.

What I did:

1) 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;
 }

2) Create this blueprint:

In your HUD blueprint graph: box selection

3 additional methods to your HUD blueprint: HUD

In your controller blueprint graph: controller

Input settings: input settings

And that's how it looks like then: result

more ▼

answered Mar 31 '14 at 03:57 AM

avatar image

marcjs
31 2 2 79

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question