Ramping Up Unity Terrain

Published February 20, 2016
Advertisement

Personal Update:


So right now, I'm flying across the country with my immediate family. We each have about 3 days worth of clothes, the Chromebook, our phones, and that's it. We gave away or donated lots of our stuff, all of our furniture, and even our cars. The remaining stuff, we crammed into the POD and finally finished loading it Monday evening. They picked it up Tuesday and started trucking it across the country. It takes an estimated 10 days to get there so it will be the 27th at the earliest before we have access to our stuff. That includes our computers! >.< But first, we'll have to find a place to live or we won't have a spot for our stuff to be delivered to. smile.png

Tuesday and Wednesday was all home repair, cleaning, and last minute tasks. It was really sad saying goodbye to my mega awesome Game Room. It was so empty. sad.png My family, friends, and I made a ton of good memories there. It was also especially profound to me when I was looking at my empty keychain. No house - no car - and most of my possessions are in my garage waiting for the donation crew to come pick them up. I'm saying goodbye to the life I've known for nearly 20 years. O.O

TODO - Pic of empty game room and key ring.

My wife has been looking at houses/apartments online and we'll be checking some out later in the week.

Development Update:


Since one of the first tools I'll be working on is a ramp tool for the level editors, I dove into learning about Unity Terrain. (The computers were the last things to get loaded smile.png ) Terrain geometry in unity is handled behind the scenes by a 2d heightmap. Each pixel on the heightmap corresponds to an area in the terrain and you can change the form of the terrain by modifying this data. Unity terrain also has the data for trees, grass, and wind zones baked in.

After my research, I decided to get a simple terrain effect working. I wanted to level out a circular platform where the user clicked. The first thing I got working was converting mouse coordinates over to terrain coordinates.

TODO - Conversion details, and code samples.

Once I had the proper terrain coordinates, modifying the terrain was a simple matter of using GetHeights to pull a list of nearby terrain cells, modifying a circular pattern to the appropriate height, and then using SetHeights to set the data.

I'm writing this entry on the plane so I'll come back and share some code samples after I find a place and get my computers back online.

I can solve the trivial case of orthogonal oriented ramps, but I need some help for arbitrarily oriented ramps. I understand how to draw a pixelated "line" of terrain on the map using something like a Bresenham line drawing algorithm, and lerping the height to create the ramp. But that would only be one cell (pixel) thick. I thought about "walking" along the path and drawing perpendicular lines of the appropriate height, but I'm worried it will generate holes in the integer terrain coordinates. Maybe not though.

I could build an orthogonal ramp, and then rotate it appropriately with some matrix math, but that assumes the ramp will be straight. If some level editor wants a ramp to curve around the terrain of a hill, the solutions I'm thinking of won't work. I'll need to allow them to drop a couple of control points and somehow trace that arbitrary path to build the width of the ramp. I need to talk to the artists to see what they want and talk to the lead developer to bounce my ideas off of him.

Next up, I worked my way through some more editor tutorials. One in particular showed me how to allow the user to place control points for lines, curves, and splines, so that's going to be useful for sure.

Sorry for such a long post. It's a long flight! My first official day is Monday Feb 22nd. My next post probably won't be until the 28th, but I'll be sure to tell you all about it. smile.png

Unity Gotchas:


GetHeight returns the height of the terrain in height adjusted units. If you have a 1200 scaled height terrain, it would return a value between 0 and 1200. But GetHeights and SetHeights return and expect float values from 0 to 1.

Unity stores the heightmap as a 2d texture. Changes to the heightmap modify that texture permanently and the changes aren't "undone" between runs. So if you're hoping to deform the terrain during a game, know that you'll need to keep a copy of the original to restore the terrain between each run.

Tip from your uncle Eck:


I'm a little low on relevant wisdom to share, so I'll give some more life advice. Don't give people two options when one of them is wrong. This is especially true for ladies and their husbands. Ladies, we want to make you happy! Just tell us what you want! :)
Previous Entry I LANDED MY DREAM JOB!
Next Entry Living the Dream
6 likes 2 comments

Comments

Eck

We looked at some houses, found one we liked but it got snatched out from under us. :( It had a Harry Potter style cupboard under the stairs for the little one, and some other cute features. But while we were looking at it, someone else was signing the paperwork. The market here is CRAZY. Houses for sale and rent don't stay up for very long at all.

That night I looked at apartments and found one that was within walking distance to an awesome school for kiddo and super close to work for me. We scheduled an appointment for Saturday, but after sitting around the hotel room for a while my wife started getting antsy and suggest we just go Friday morning instead.

We went, looked at it, and liked all the cool features (heated pool, fitness room, shared lobby, basketball court, close walking distance). We decided to be the snatchers and started filling out the paper work right then. While doing that, one guy showed up without an appointment, and two different couples showed up with appointments at noon to look at it.

Provided my background check comes back clean, the apartment is ours. :D

Next up, car shopping.

February 20, 2016 02:29 PM
ferrous

Yeah, housing/rental market is nuts right now, houses in my neighborhood are going for more than they ever have in the past. (Even at the height of the bubble)

For your ramps, I think walking incrementally might be okay, as long as it's a small enough amount. If you can, I suggest going with Catmull-Rom for your curve, control points that go through their point are easier to deal with. You could do something like have the user/designer specify two lines, one for each side of the ramp, and interpolate between the two lines. (and by lines i mean set of points)

February 21, 2016 05:31 AM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement