• entries
    42
  • comments
    139
  • views
    51005

Ramping Up Unity Terrain

Sign in to follow this  

1440 views

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! :)

Sign in to follow this  


2 Comments


Recommended Comments

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)

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now