# Create a castle wall using modifiers?

I am trying to create a curved castle wall using the array and the curve modifier.

This works fine for a wall on a flat surface. I'd like to add some terrain by also changing the curve on the z-axis.

As depicted in the image above this seems to work fine. However the merlons (extended part on the wall) start to lean and follow the curve as well.

Question: Is there a way to restrain the deformation on the merlons? I would like to keep all the vertical lines vertical. (See handmade mesh below) Maybe anyone has an idea for a better workflow?

• Should the merlons on a sloping hill look like stair steps to overcome the height difference? Feb 24 at 19:33
• Not necessarily. I would be happy with a wall that could follow soft hills and terrain differences. Similar to this photo of Yorks townwall ichef.bbci.co.uk/news/976/cpsprodpb/BC50/production/… For steep hills I guess I would model a specific mesh. Feb 24 at 19:53

I think it's easier to use a flat curve and than displace the wall based on the terrain. The starting setup I would use has mesh object with an array modifier and curve modifier pointing to a 2D curve. Then we have the 3D terrain as a separate mesh:

Pick the castle wall object and add a node modifer. First thing we need to do is to "apply" the modifier stack to the geometry of the object, so we add the Realize Istances node:

Then we need to displace the geometry of the wall up above, so we add a "Set Position" node that has as input the position field:

The offset value can't be a single value, or the walls will go up all by the same amount. We should sample wall geometry points to find the nearest point of the surface and transfer the only the Z value (see the position field multiplied by 0,0,1).

Sampling node may introduce some imprecisions whit this simple setup. You can achive better results by taking into accounts only the projection of the surface like this:

Finish by adding another node setup to check for faces that looks up (normal = 0,0,1) and scale them by zero on the Z axis

Final result:

• Thank you for the detailed answer. I will give this a try! Feb 25 at 10:50