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:

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:

The blueprint used to spawn the grid is the following:
fa3f0bd6d6b3faa29f9bd3f0dbb98cedf8c0b490.jpeg

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.

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.

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:

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.

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.

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.

So, back at home, here is an update:

GetZ function:

Blueprint with the function added:

Here are the results:

This one looks partially good, even tho it isn’t following the landscape deformation correctly.
626fa200f67b15ac0f90ddb5306d563328b2b24d.jpeg

This other one worked somewhat closer as well.
23912de9e0b6b84a19d1fd251a1fed859435e445.jpeg]

but whenever there’s a slightly bigger inclination, it doesn’t work:
da82e960b21e65f4a63375a7fcf94c90dea85fed.jpeg

Any ideas what I’m doing wrong?

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:

Here you can see it in action:

Feel free to ask if you have any questions.

1 Like

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.