Easy-Dro Posted August 20, 2016 Share Posted August 20, 2016 (edited) Hello people, I want to make a Fire Emblem game with Unity for a project from school but the true is that I don't have any idea of how can I make a grid-based scenario in Unity. I'm not a completly begginner with Unity because I have made 4 simple games with Unity (the last one was the survival shooter from the official webpage), but I'm still a begginner, so there are a lot of things that I still don't know. I have a small idea, but I don't know how can I apply it to Unity. I have been thinking about this and the most easy thing I can think is to create a plane in the scene and put a script with a matrix of Game Objects here, that matrix should be the grid of the game, but the thing is that even if I do that, I don't know how to show the matrix in the plane. How could I make a grid floor with Unity? Some people have recommended me the Grid Framework plugin, but I don't want to spend money with plugins, at least for now. Thank you very much for the help. Edited August 20, 2016 by Easy-Dro Quote Link to comment Share on other sites More sharing options...
Enaluxeme Posted August 20, 2016 Share Posted August 20, 2016 I don't know about unity, but making a game with a grid system is one of the easiest things ever: just handle the grid with a matrix. Actually, you want two matrices: one for the units and one for the terrain. Quote Link to comment Share on other sites More sharing options...
Agro Posted August 21, 2016 Share Posted August 21, 2016 probably the hardest thing you would have to deal with would be programming the AI, I don't imagine the rest of it is particularly hard Quote Link to comment Share on other sites More sharing options...
Easy-Dro Posted August 21, 2016 Author Share Posted August 21, 2016 I was thinking about using 2 matrix aswell because I did something similar in the past at school with a small game where we have to create a small AI moving in a matrix, but the thing is that I don't know how can I connect the scenario with those matrix. I say, I can create a bunch of sprites or blocks but I don't know how can I connect them to the matrix. Is a good idea making a script who has 2 static matrix and add it to each sprite or block of the scene? I can't think in any other way of doing this. Yes, the AI will be hard as hell but sure it's the most interesting part and the one where I'll learn more. Thank you for reply. Quote Link to comment Share on other sites More sharing options...
Augestein Posted August 22, 2016 Share Posted August 22, 2016 Assuming that it is 2d... Go for a map or sorted dictionary of some sort. You can have your two dimensional array and store the terrain itself in the map/dictionary. Quote Link to comment Share on other sites More sharing options...
Agro Posted August 27, 2016 Share Posted August 27, 2016 If you ever get that far, we tore apart the AI of FE7 in this thread over at FEUniverse: http://feuniverse.us/t/fe7-the-official-ai-documentation-thread/348 It might help with your programming at some point. Quote Link to comment Share on other sites More sharing options...
InvdrZim13 Posted August 27, 2016 Share Posted August 27, 2016 I'm pretty sure blindcoco is making an FE type game with unity Quote Link to comment Share on other sites More sharing options...
Easy-Dro Posted September 28, 2016 Author Share Posted September 28, 2016 (edited) Thank you all for reply, guys. It worked just as you say, I did the grid mapping the indices of the terrain matrix to Unity's coordinate system (so if TerrainGrid[1][3] had a unit, you'd see a sprite at (x = 1.00, y = 3.00)), I also make an interface that shows all the stats of the unit that you click to test if this works and it does! I made here 2 controls: the first is the keyboard and the other the mouse, so if I want to adapt the game to Android in the future I'll have alredy the controls. The true is that at the first was really confusing because I didn't know how to create everything, so I create all things in the Start method of every script but I tested it and it didn't work (since if like I'm creating everything in different threads and I had no control of it), so I make a controller class that creates everything (the map, the matrices, the pointer, the units...) and with this it worked perfectly. It took me this long because I'm studying web programming, so I dont have many time to deal with this, another reason is that I'm using sprites from Awakening, I take 20 different units, and every unit has 40 sprites, that is 400 sprites in total, lol. Also, the animations, I have created 10 animations per unit, so that makes a total of 200 animations (ones are shorter than others, of course). I'm a bit frightened of how I will connect all those animations with the character but well, time to time, I did animations before so I don't think this will be difficult, but it will be very long. Now I'm stuck with the movement, when I click on a character, it will show his stats and when I click again, It has to show me the squares he can move. I managed to make a method that recieve a character and depending of the distance he can move, it makes the blue and red squares arround it, and I also made a small filter that makes the method not to make squares out of the map. But the true is that I have to re-write that code because it doesn't work how I expected, because if I also have to filter the distance where the units can move, I have to filter the forest, the mounstains, the rivers... and the truth is that I have no idea of how can I do that and my code doesn't work for that. ¿How can I get the squares where a unit can move with every filter? This is what I get with my code: (this will be long) (Sorry for the language, since this is a project for school, I have to do this with my native language) As you see here, Priam can move 5 squares, so I get the squares he can move, the thing is that, my algorithm doesn't work to filter the map and cut his movement when the square is a river, forest or mountain because I did this this way: First I make a cross making 4 lines per separate in the same loop: And after that I make the rest like one of the first programming activities that you usually do at school: And because of this I can't filter the movement properly. I should get something like this: And filter it when for example there is a forest in a square: Or get something like this: But I don't have any idea of how can I do this. Edit: By the way, I have 2 matrices: 1 for units and the other for the terrain, just like Enaluxeme said, but I still don't know how can I cut the movement of... 3 rows? like that, It's a bit crazy. Someone knows how could I get this? This pisses me off because I'm stuck with the algorithm and I don't know how to solve this. For the IA I think it can be easy (if you don't want to make a complex IA of course), I just have to get the squares where a unit can move and make a method with a bunch of if/else. Thank you for reading. Edited September 28, 2016 by Easy-Dro Quote Link to comment Share on other sites More sharing options...
Eliwan Posted September 28, 2016 Share Posted September 28, 2016 (edited) But I don't have any idea of how can I do this. Edit: By the way, I have 2 matrices: 1 for units and the other for the terrain, just like Enaluxeme said, but I still don't know how can I cut the movement of... 3 rows? like that, It's a bit crazy. Someone knows how could I get this? This pisses me off because I'm stuck with the algorithm and I don't know how to solve this. Check terrain costs. Don't iterate through each spot that is normally available to move through, but instead check per tile what terrain is beneath and calculate the cost of movement through that tile.This code snippet is from KK20's AWXP Engine and I think it's helpful to have something to directly reference: #----------------------------------------------------------------------------- # * Calc_Pos - Find what tiles to highlight to determine range #----------------------------------------------------------------------------- # unit = Class Unit # range_max = maximum range that can be achieved # range_min = minimum " " # type = what tiles are we going to work on? # >> "move" - Move range # >> "attack" - Attack range # >> "direct" - 4 tiles around the unit # >> "vision" - Unit's vision range # x , y = If wanting to get tiles from a specific spot and not a unit's x/y #----------------------------------------------------------------------------- def calc_pos(unit, type = "all", x = nil, y = nil) # Stores all the x-y coordinates of possible spots positions = [] if type == "move" or (type == "attack" and unit.max_range == 1) # Sets maximum move range based on remaining fuel range_max = (unit.fuel < unit.move ? unit.fuel : unit.move ) #In Advance Wars units have a Fuel amount that dictates their maximum move #For your case you'd want to just have the Move of the unit (which would be probably mostly dependant on their class) case range_max when 0 # Adds current actor position since it can only move 0 spaces # Actor = unit positions.push([unit.x, unit.y]) # If unit can actually move some spaces... else # setup the values of the following arrays positions = [[unit.x, unit.y]] #-> Stores [x,y] of every space that unit can move onto route = [[]] #-> Defines the directions to get to position. Elements work in conjunction with position's. cost = [0] #-> Movement cost to get to position. Work in conjunction with positions and route more_step = [0] #-> Stores index values so that it can check which positions to process possible additional spaces. for i in more_step x = positions[i][0] # X-coord of space y = positions[i][1] # Y-coord of space c = cost[i] # Space's cost (e.g. it takes 3 move points to get here) #Begin finding all possible paths. Starts with DOWN if unit.passable?(x, y+1) #Can the tile below be walked through #For other directions, instead of adding 1 to Y, #you'd subtract 1 from Y for up; (x, y-1) #subtract 1 from X to get left; (x-1,y) #add one to X to get right. (x+1, y) tt = (unit.army.officer.perfect_movement ? 1 : ($game_map.get_tile(x,y+1).move_cost(unit))) #get move cost of tile that is below tt += unit.army.mcosts #Powers that increase move costs across all terrains use this to increase it if c+tt <= range_max #if current route cost <= move_range if positions.include?([x, y + 1]) #is this spot already found? index = positions.index([x, y + 1]) #find element of this spot if cost[index] > c+tt #is current route found less costly than original? route[index].clear #reset existing route route[index] = route[i] + [2] #set new route cost[index] = c+tt #replace cost table for pos if c+tt < range_max #is there another spot we can reach because of this reduced cost? more_step.push(route.index(route[i] + [2])) end elsif cost[index] == c+tt #is new route just as costly? if clean_route(route[i]+[2], route[index]) #does the new-found route have less turns than current route? route[index].clear #reset existing route route[index] = route[i] + [2] #set new route end end else #this spot is newly founded...let's add it positions.push([x, y + 1]) #add position to positions array route.push(route[i] + [2]) #add route for position cost.push(c+tt) #add cost required for position if c+tt < range_max #enough move spaces left to find more spots? more_step.push(route.index(route[i] + [2])) #push more step for position end end end end #The process is much the same as above for the other 3 directions Edited September 28, 2016 by Bedimal Eliwan Quote Link to comment Share on other sites More sharing options...
Easy-Dro Posted September 30, 2016 Author Share Posted September 30, 2016 (edited) Umm... so it's like using A* or Dijkstra algorithm. I don't know anything about IA but I will study about it and post the results. Thank you very much for your answer and the example. Edited September 30, 2016 by Easy-Dro Quote Link to comment Share on other sites More sharing options...
Eliwan Posted September 30, 2016 Share Posted September 30, 2016 (edited) Yeah it definitely has some elements from there I didn't know about those things though -- much thank for the learning opportunity Edited September 30, 2016 by Bedimal Eliwan Quote Link to comment Share on other sites More sharing options...
Easy-Dro Posted October 1, 2016 Author Share Posted October 1, 2016 Fucking finally, I spend arround 5 hours yesterday studying the algorithm and 8 hours today trying to apply it, but I finally have it: Well, it's time to start moving the characters... but I think I'll leave it for tomorrow xD Thank you all for the help. Quote Link to comment Share on other sites More sharing options...
Easy-Dro Posted August 17, 2017 Author Share Posted August 17, 2017 Well indeed it was possible, I wanted to add more things like weapons, more maps, a much more intelligent IA but I had to left them out because of the time. Anyway I'm happy with the result, this is my first game after all. Initially I wanted to do 2 versions of this game: PC and Mobile, but for some errors with the rendering and the time I had to left the Mobile one. Otherwise I would like to fix this one day. I also wanted to thank you all for your help and share the result: Note: I finished this last year, but I was busy/lazy to make this video :) Quote Link to comment Share on other sites More sharing options...
copywright Posted January 31, 2021 Share Posted January 31, 2021 Pretty cool stuff here. Doing the same thing right now, wish I was around to help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.