Announcement

Collapse
No announcement yet.

Creating an expandable structure/building

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Creating an expandable structure/building

    Hello dear forums.
    .
    I've reached a quite critical stage in my game. Here's a few lines to briefly describe what the goal is (i'll go into further details as this post comes along):

    I'm trying to create a building where the player can expand the building based on "blocks" of rooms. This would give the player further area to place various gameplay objects. The functionality that displays where the player can expand, should be based on the current structure of the room. Here's a quick image that shows what I mean. The green box is the current building, and the dashed red lines is the expandable block options.
    Click image for larger version  Name:	Unavngivet.png Views:	1 Size:	624 Bytes ID:	1575775




    The player can click on the expandable areas to expand the building to that certain block, spawning in a new "block" of the building. Simultaneously, I wish for the walls to be removed on the current structure. If the player click the right down most expandable block, the wall blocking from the right down most current structure (green), should be removed.

    Current ideas
    My first ideas was to do a line trace for each building "block" in all four directions (north, south, east and west), but after realizing that my building might be the size of 8 blocks, that would mean 4 line traces per block whenever the user expands, that would make 32 line traces. I'm still somewhat new to Unreal Engine, but I'm guessing 32 line traces is not healthy for performance.

    My second idea was to use a matrix to keep track of what block are available for expansion, and which blocks are occupied by an already existing block. This would however limit me to a certain size of the building, which I'd like to eliminate if possible.

    Unfortunately, these are the only ideas I can think of for the time being, but I'm hoping that Unreal Engine might have some sort of tool to help with these issues, but I'm not sure what exactly. I'm hoping some of you here on the forums, might have some suggestions.

    If you need further information to find a solution, please let me know
    Last edited by Detilium; 01-22-2019, 03:45 PM.

    #2
    Hello,

    Looks like a simple coordinate system to me

    I would use a map with IntPoints(struct FIntPoint) as the key, and a block object as the value.
    It's important not to use FVector2D because we do not want floats, but integers. The start of your building would be (0,0), and each adjacent block would add or remove 1 from one coordinate.

    To check whether or not an area is expandable, simply check if the corresponding key exists. If it doesn't, you can expand!
    Same thing to solve your walls issue: Check if there's an area already expanded on the other side of the wall

    Comment


      #3
      Two questions, first when you add a new block, does it become part of the room as a whole. If so you have more than 32 potential traces. And second, what's the camera perspective?
      Joseph Wilcox
      [Technical Director] WisEngineering
      https://www.wisedrl.com

      Comment


        #4
        Originally posted by Altrue View Post
        Hello,

        Looks like a simple coordinate system to me

        I would use a map with IntPoints(struct FIntPoint) as the key, and a block object as the value.
        It's important not to use FVector2D because we do not want floats, but integers. The start of your building would be (0,0), and each adjacent block would add or remove 1 from one coordinate.

        To check whether or not an area is expandable, simply check if the corresponding key exists. If it doesn't, you can expand!
        Same thing to solve your walls issue: Check if there's an area already expanded on the other side of the wall
        I'm definitely trying this as the first thing, as it actually makes pretty good sense. I suppose the map functions just like dictionaries in C#, which makes it a bit easier for me since I'm coming from a C# job.
        Originally posted by Joe Wilcox WisE View Post
        Two questions, first when you add a new block, does it become part of the room as a whole. If so you have more than 32 potential traces. And second, what's the camera perspective?
        It doesn't become part of the room per say. Each block is it's own actor. The perspective is like a regular RTS, and the player has the functionality to rotate the view, as well as zoom in and out.

        Comment


          #5
          Originally posted by Altrue View Post
          I would use a map with IntPoints(struct FIntPoint) as the key, and a block object as the value.
          Quick question. At first I thought of just using the IntPoint (0,0) for my default block, but whenever the player wish to expand, I need to know where to place the new expansion block. The size of my block is 500x500, so I'm thinking of settings the default IntPoint to (0,0), then:
          • the block to the left of the default block, would be IntPoint (500, 0)
          • the block to the left of the default would be IntPoint (-500, 0)
          • the block above the default block would be IntPoint(0, 500)
          Does this makes sense or should I just use the following:
          • Left - IntPoint (1,0)
          • Right - Intpoint (-1,0)
          • Above - IntPoint (0, 1)
          Using the first example, with the width of my blocks, I'm able to convert this to world space when spawning the new block?

          Comment


            #6
            I would strongly advise against using coordinates influenced by the size of your block. (i.e IntPoint(0,500))

            What your data structure is trying to represent, is a bunch of cells of equal size. By using 1 as the unit representing one cell, or one block, we leverage a key feature of the map which is that there can only be one key to represent one block position in the world. If you were to use (0,500) instead of (0,1), you could have another block in the map at (0,499), or (0,501), etc... Even though the blocks in this situation would overlap.

            Put in a more abstract way, the rules for storing your block information would not match the rules for placing your blocks. It's not only inelegant, it also opens the doors for a new type of overlap bug that you just couldn't have with a data structure which very nature enforces the no-overlap rule.

            One other thing: By using 1 as the unit representing one cell, you are not constrained by the size of the cell. If tomorrow you need your cells to be 450x450 instead, the first cell would still be (0,1), the second (0,-1), and so on...

            To convert the relative coordinates to world-space coordinates, simply multiply the IntPoint by the dimentions of the cell. For instance: Coordinates x Block Size = (-1, 2) x (500.0f, 500.0f) = (-500.0f, 1000.0f)
            Note that I'm using floats for your block size and final world-space coordinates, as these two values actually mean something in world-space.
            Last edited by Altrue; 01-24-2019, 09:06 AM.

            Comment


              #7
              Originally posted by Altrue View Post
              To convert the relative coordinates to world-space coordinates, simply multiply the IntPoint by the dimentions of the cell. For instance: Coordinates x Block Size = (-1, 2) x (500.0f, 500.0f) = (-500.0f, 1000.0f)
              Note that I'm using floats for your block size and final world-space coordinates, as these two values actually mean something in world-space.
              Of course. I initially though that this would complicate things with my default base block since it's at IntPoint (0,0), but I would never need to calculate the world space for this block, as it cannot be removed, added, or edited.

              My bad, thanks for the input however. I do see the potential for bugs in a scenario where the block size would be represented in the IntPoint.

              Comment


                #8
                Altrue Just got this implemented, and it works just as planned. I really appreciate the time you took to help me

                Comment

                Working...
                X