Announcement

Collapse
No announcement yet.

Grid/Cell collision and movement

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

    Grid/Cell collision and movement

    Hello! I am having trouble today and would like some help.

    I am currently part of a small team of hobby game makers and I have been tasked with creating a grid based movement system for a simple top down style RPG I have been strictly told to stick with Blueprints. Anyway, my thought process was to create a grid of a certain size, lets say 16x16 as standard for old style RPGs, and then stick object location data in a 2d array for collision. Unfortunately there aren't any 2d arrays, and I can't get my head around the small amount of ways to kind of create them.

    So now I am completely stumped as to what to do. I have been working on this for a few weeks straight now and have gotten absolutely nowhere. I have created a grid actor that creates a bunch of cells either by loop adding additional collision boxes, or loop spawning multiple actors that is just a Blueprint actor with a collision box. Both methods seem to have the same amount of performance depending on how many I create. So now I have a grid, and even that I'm not quite so sure is even the best way of creating a grid, but it's all I have at the moment. Anyway, I'm stuck on how I can do the following:

    1. move the player pawn to the next cell without resorting to setting actor location, using a timeline, and updating a vector variable when it finishes to store the new location. I don't like this approach because it isn't grid based movement, it's just moving a set amount and this would work horribly with moving objects.

    2. Storing object locations in a variable so that the player pawn or a moving object can not access that cell. Basically I want to set the next cell as inaccessible before the player or moving object actually moves so that there is no possibility of two objects entering the same cell.

    Desperate isn't far from what I am right now with this. I've started working on other things at the moment because this is really starting to hurt my head, but I can't do much because it's an integral part of the project that many things rely on.
    Last edited by Shaun_C; 10-13-2017, 06:13 AM. Reason: Added tags

    #2
    You can make a 2D array by making a struct with an array. And then having an array of said struct. So now each index of the array would represent a X coordinate and the index of the struct array would present a y coordinate.

    However, I found it pretty nice to create a dictionary/map, where the key is a struct with int members representing the coordinate and the value whatever data you need. By giving the Grid/Cell actor its coordinate, you can make it communicate with the whole system and the system to a specific grid/cell. For thing like checking if it is occupied, adjacent or whatever else.
    Last edited by ste1nar; 10-13-2017, 08:41 AM.

    Comment


      #3
      Hi, thanks for the response.

      I like the dictionary/map method as I could use this for other things, although for a grid I'm having a hard time visualizing how to actually implement this. It's the biggest step forward I've had in weeks, and I really appreciate the help.

      Comment


        #4
        You Can check my Basic TopDown under "2D Templates" (Free movement using character class) or Sokoban template under "Mobiles Templates" ( Grid based movement)
        Last edited by Mhousse1247; 10-13-2017, 12:10 PM.
        Website [ LINK ]
        Twitter [ LINK ]
        Support ! [ LINK ]

        Comment


          #5
          For me, the first step is to fill the Grid Map with coordinates. Right now I'm assuming it's a chess-like grid, rather than a hex grid or something.

          Click image for larger version

Name:	Grid1.png
Views:	126
Size:	72.8 KB
ID:	1368988

          As for what values the map needs to hold, maybe you only need a reference to an actor.

          Anyway, then spawning the cell actors based on the coordinate and cell size.

          Click image for larger version

Name:	Grid2.png
Views:	125
Size:	164.0 KB
ID:	1368989

          So that's the basics of it. It should be pretty easy to spawn a chess type plane of actors with cubes or something.
          And using some algorithm, more custom shapes. Here's a layout spawned based on letters and symbols inside a data table:

          Click image for larger version

Name:	layout1.png
Views:	122
Size:	136.5 KB
ID:	1368990

          Comment

          Working...
          X