Announcement

Collapse
No announcement yet.

Spawing a Grid based on landscape.

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

    Spawing a Grid based on landscape.

    Hey, hope you guys are doing great!
    This is my first post on UE forums, even though I’ve been reading and checking it since UDK. Sadly, that does not means I know a lot of the engine, on the contrary, I’m have trouble with what I think should be really simple things.

    Recently, despite of not having that much time, I’ve decided to start working in a pet project, one I’ve been wanting to try my hands on for some time now.

    The goal is to create a “real time, turn based combat”. The main point is that I want to have grid-based movement for the character and turn-based action.
    I’ve tried some tutorials and learned the following: I cannot have grid-based without spawning a grid to move on. The issue is that I wanted an ‘open map’ feeling or something similar.
    Procedural Room Generation helped me understand how to spawn a grid and how to use it to determine movement and how to set a ‘turn’ order.

    So, I thought: “Well, why not create the grid, based on the player location when ‘combat starts’ and use it during ‘combat’ to determine movement?”
    The solution seemed at first easy to achieve could potentially solve my problem.

    So, to test my solution, I created a small event on blueprint level, to spawn the grid once the F key is pressed:
    Click image for larger version

Name:	OpenWorldTestProject - Unreal Editor.jpg
Views:	1
Size:	216.1 KB
ID:	1160953

    As you can see, the grid spawn at the character location, which is good, however it doesn’t follow the terrain deformation, as you can see in the following image:
    Click image for larger version

Name:	OpenWorldTestProject - Unreal Editor_2.jpg
Views:	1
Size:	258.9 KB
ID:	1160954


    The blueprint used to spawn the grid is the following:
    Click image for larger version

Name:	GridMap.jpg
Views:	1
Size:	120.6 KB
ID:	1160955


    The question is: How to set the Z coordinate to match the one in the landscape? I tried creating a function that would pass the xy position and use a linetrace based on it to return the z, but it didn't worked as I hoped It would.

    Any ideas?


    P.S: Sorry for my poor English, it’s not my native language.

    #2
    You said you used a line trace, how did that not work as you hoped? A line trace is exactly what I would've used.
    Marketplace Assets

    Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
    Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
    Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

    Comment


      #3
      I’m not at my computer at the moment, so I can’t provide the exact blueprint I used.
      I created a function that would receive the xy, and based on this blueprint:
      Click image for larger version

Name:	21686-distancetrace.png
Views:	1
Size:	219.3 KB
ID:	1087207

      I created a modified version which was supposed to return the z. It worked to a certain point, but the position the linetrace as getting was wrong, so the tiles were being placed based in other location then the one they spawned.

      Comment


        #4
        Why are you minusing the location from the trace start? All you want is the actual hit location and that should be your Z height. Personally I would take a trace at the end location of the square and then using the end location of the previous trace you can then set the angle of the square to match up to the terrain.

        Comment


          #5
          Originally posted by ZoltanJr View Post
          Why are you minusing the location from the trace start?
          The blueprint above isn’t the one I used. I based mine on that. I set the trace start at the same xy coordinates from the floor tile and used the hit location Z, as you said yourself.

          Only it didn’t worked. I’ll provide the code later, I’m at work at the moment and don’t have access to the blueprint I created.

          Comment


            #6
            So, back at home, here is an update:

            GetZ function:
            Click image for larger version

Name:	GridMap_2.jpg
Views:	1
Size:	120.1 KB
ID:	1087229

            Blueprint with the function added:
            Click image for larger version

Name:	GridMap_3.jpg
Views:	1
Size:	95.1 KB
ID:	1087230

            Here are the results:

            This one looks partially good, even tho it isn't following the landscape deformation correctly.
            Click image for larger version

Name:	OpenWorldTestProject - Unreal Editor_4.jpg
Views:	1
Size:	176.1 KB
ID:	1087231

            This other one worked somewhat closer as well.
            Click image for larger version

Name:	OpenWorldTestProject - Unreal Editor_3.jpg
Views:	1
Size:	234.9 KB
ID:	1087232]

            but whenever there's a slightly bigger inclination, it doesn't work:
            Click image for larger version

Name:	OpenWorldTestProject - Unreal Editor_5.jpg
Views:	1
Size:	233.2 KB
ID:	1087233


            Any ideas what I’m doing wrong?

            Comment


              #7
              Hi berjkley, I've made something pretty similar to what you're trying to achieve. I use downward line traces at all the locations of my grid tiles (which are held in an array of vectors). If the traces are a hit I update the locations in the array to take the height at where it hit into account. To make the tiles conform to the underlying landscape I use decals instead of instanced static meshes (though I have included the option of using ISMs as well, but I think these are not well suited for such landscapes). The part of the blueprint that does this is dependent on a lot of other functionality in the toolkit, but I hope this snippet of blueprint code will help you:

              Click image for larger version

Name:	j4YlgF9.png
Views:	1
Size:	433.1 KB
ID:	1087234

              Here you can see it in action:

              http://www.youtube.com/watch?v=xqVTbk-FEBU&t=5m40s

              Feel free to ask if you have any questions.
              Advanced Turn Based Tile Toolkit (Marketplace - Support)

              Dungeon Crawler Toolkit (Marketplace - Support)

              Discord

              Comment


                #8
                Okay! Thanks for the help! I'll dig in and see if I can make it work out!

                Comment


                  #9
                  Originally posted by berjkley View Post
                  Okay! Thanks for the help! I'll dig in and see if I can make it work out!
                  I realize that this may not work for you, but using decals, you can get the tile to paint itself onto the landscape, which will look good.
                  Marketplace Assets

                  Advanced Mobile Input: Marketplace Page | Support Thread ――― Easy Input Remapping: Marketplace Page | Support Thread
                  Multiplayer Blueprint Chat System: Marketplace Page | Support Thread ――― Closing Credits System: Marketplace Page | Support Thread
                  Minesweeper Template: Marketplace Page | Support Thread ――― Maze Creator: Marketplace Page | Support Thread

                  Comment

                  Working...
                  X