Terrain Troubles

I’m using this code in a whole bunch of strategy game units, and it’s totally not working. It only updates when a unit moves, to save processor. Even when the terrain is flat as they walk around their y values jump between a couple different values.

function updateHeight() {
	var heights = land.GetHeights(transform.position.x,transform.position.z,1,1);
	transform.position.y = heights[0,0];
}

What am I doing wrong?

P.S:
I do have to run this a whole bunch (up to 8000 times) per frame, so it would be awesome to figure out a way around dynamic casting. I don’t know C#, so that’s out unless someone wants to throw me some quick code.

You want SampleHeight; GetHeights gives you the heightmap info, which is nothing to do with vectors. (Also that code you posted doesn’t have dynamic typing.)

–Eric