• Create Account

## Smooth character movement over a heightmapped terrain.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

5 replies to this topic

### #1Wilhelm van Huyssteen  Members

1144
Like
0Likes
Like

Posted 17 August 2012 - 02:30 AM

Hi.

Assume that Z is the up axis.

I have a heightmapped terrain. A 1024x1024 texture maps to a 1024x1024 vert mesh that represents a 1024m x1024m game area (In reality it actualy gets splitted into much smaller meshes so proper LOD and frustum culling can happen but thats irrelevant to this question). I have taken the characters x and y coords. Rounded them to the nearest Integer and used that to retrieve the height value from the heightmap texture and then I set the characters z coord to that value. Now my character can move over the terrain but its ofcourse horribly jumpy.

I need to take the height values of the 4 heightmap pixels around my character and based on where he is reletive to those 4 pixels work out the final height value but im strugling with that abit.

what i tried so far was simply this:

aDist,bDist,cDist,dDist; //characters distance to the 4 surrounding pixels (on the xy plane).
aHeight,bHeight,cHeight,dHeight; //the 4 surrounding pixels height value\

totalDist = aDist + bDist + cDist + dDist;
bDist = bDist / totalDist;
cDist = cDist / totalDist;
dDist = dDist / totalDist;
finalHeight = aHeight * aDist + bHeight * bDist + cHeight * cDist + dHeight * dDist;

Unless i made a mistake somewhere in my code (wich is very possible ) this is not the solution.

Any help appreciated. Thnx in Advance!

Edited by Wilhelm van Huyssteen, 17 August 2012 - 03:32 AM.

### #2oggs91  Members

421
Like
1Likes
Like

Posted 17 August 2012 - 05:06 AM

assuming u use a regular rectangular grid in the mesh, u have to determine what triangle your player steps on

then use the three height values of the corressponding triangle as barycentric coordinates to calculate the height

### #3oggs91  Members

421
Like
0Likes
Like

Posted 17 August 2012 - 05:07 AM

with 4 surrounding pixels u mean the vertex positions?

### #4Wilhelm van Huyssteen  Members

1144
Like
0Likes
Like

Posted 17 August 2012 - 06:04 AM

Yes. I should have been more clear. with the 4 surrounding pixels I meant the vertex positions of the 4 surrounding vertices in the terrain mesh (wich corresponds with the "4 surrounding pixels" in the texture).

And yes i use a regular rectangular grid in the mesh.

Edited by Wilhelm van Huyssteen, 17 August 2012 - 06:08 AM.

### #5Inferiarum  Members

739
Like
1Likes
Like

Posted 17 August 2012 - 12:01 PM

### #6Wilhelm van Huyssteen  Members

1144
Like
0Likes
Like

Posted 19 August 2012 - 10:50 AM

I got it working perfectly using barycentric interpolation. Thnx for pointing me in the right direction oggs91.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.