0
\$\begingroup\$

My current world is a flat 2D plane.

I want to make the terrain 3D, like hills, bumps, etc. If I tell a unit to go to a position (x, y) in 2D, how do I make sure the unit is always at ground level?

For example, if x, y is above the current position in 3D?

I am defining terrain height using a height map, and generating a simple mesh from it. Path-finding will remain flat 2-d, and can project to 3-d.

\$\endgroup\$
6
  • 3
    \$\begingroup\$ How do you intend to define your terrain height? Are you using a heightmap, voxels, polygon terrain or perhaps something entirely different? The answer would depend on your preferred solution. \$\endgroup\$
    – Philipp
    Mar 2, 2021 at 11:21
  • \$\begingroup\$ I am using a height-map, I have updated my question. I am new to map generation so I didn't think to include it. \$\endgroup\$
    – Tree3708
    Mar 4, 2021 at 0:03
  • \$\begingroup\$ It sounds like you could simply compare the adjacent (x,y) position's height against the height at your current position, and if it's above a threshold maximum increase/steepness, do not try to move there. But maybe I'm misunderstanding what you're asking? \$\endgroup\$
    – DMGregory
    Mar 4, 2021 at 0:32
  • \$\begingroup\$ I mean that if a unit moves to pos x,z, and the height at that position is different from the start, I dont want the unit to move in a straight line there, I want it to stay attached to the ground. Like on a sloping hill, direction from point A to B (bottom to top) is a straight line, but the unit would be flying then. \$\endgroup\$
    – Tree3708
    Mar 4, 2021 at 0:36
  • 3
    \$\begingroup\$ Would you not simply set the height of the unit to the height of the terrain under it after each step? Can you show us the code you're using and the "flying" artifact you're getting, so that we can help you debug it? \$\endgroup\$
    – DMGregory
    Mar 4, 2021 at 8:42

0

You must log in to answer this question.

Browse other questions tagged .