Advertisement

Simple method for implementing terrain collision?

Started by December 14, 2016 01:22 PM
23 comments, last by Norman Barrows 7 years, 11 months ago

You're going to want to interpolate between the 4 nearest heightmap positions. There are two ways to do this.

The first way is to just bilinear interpolate using the objects fractional XY position, interpolating (edit:) the heights of both p1--p2 and p3---p4 along the X axis (if p1-p4 are laid out in a 'Z' shape). Then interpolate along the Y axis using the object's fractional position between the top edge and bottom edge of the terrain grid square, interpolating the two height values resulting from the first X axis lerps.

The second way is better suited if your terrain grid squares are being rendered as a pair of triangles, which means you only want to interpolate between the 3 points that the entity is above, instead of all 4. All you have to do is determine which triangle's right-angle the entity is closest to, and then interpolate between the height of the points of that triangle.

If you use the first method, and you are drawing two triangles per heightmap square, you could get entities that interpolate above/below the ground a bit, but it's much simpler to do.

[ deftware.org ]

deftware, haven't seen you in a long time. Thanks for posting. :rolleyes:

You're going to want to interpolate between the 4 nearest heightmap positions.

Why do I need to interpolate? You mean that my movement can be smoother?

Can't I just use a ultra high resolution heightmap or something?

My movement seems fine for now, although I noticed it could be smoother.

Can you elaborate more on this, more on the "why" part, I mean? :huh:

Advertisement

Can't I just use a ultra high resolution heightmap or something? My movement seems fine for now, although I noticed it could be smoother. Can you elaborate more on this, more on the "why" part, I mean? :huh:
More pixels doesn't give you more precision in height.

Assume a standard greyscale heightmap. That gives you 256 heightlevels. I don't know how your world looks, but lets assume height runs from 0 to 100.

That means grey-level 0 == height 0, and grey-level 255 == height 100. ie height = grey-level * 100/255.

That means height at grey-level 1 = 1 * 100 / 255 = 0.39. The question is now, is a vertical jump of 0.39 acceptable (the smallest possible jump you can express in grey-scale).

In any case, since grey-scale goes up or down in full units, there will always be jumps no matter how small.

Interpolation adds a smooth transition between the different height levels, which means you never see a jump.

Interpolation adds a smooth transition between the different height levels, which means you never see a jump.

Oh, I got it. So the bigger the difference between the lowest and highest point on my map is, the bigger the jump is.

You sold me interpolation, guys. I'll do it. :lol: I'll do the simplest one.

Oh, I got it. So the bigger the difference between the lowest and highest point on my map is, the bigger the jump is.

no, the bigger the smallest possible height difference is between some altitude and the next one up or down, the bigger the jump is. IE if you use a 256 grayscale with one unit = 0.1 meters., your heightmap can store values from zero to 25.5 meters, at a resolution of 0.1 meters. its a step function. like a staircase. interpolation turns it into a linear function, like laying a flat board over the staircase. it goes from zero to 25.5 meters with the resolution of floats or doubles - your chose of implementation.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement