Get 2D Position on Height map of a Terrain?
by Peng Du · in Game Design and Creative Issues · 03/14/2007 (8:34 pm) · 2 replies
Hi,
I'm new to Torque, so what I ask will be silly : )
I have a height map generated terrain, this terrain is tiled.
How can I transform the world position of the player to the position on the height map?
Thanks in advance!
I'm new to Torque, so what I ask will be silly : )
I have a height map generated terrain, this terrain is tiled.
How can I transform the world position of the player to the position on the height map?
Thanks in advance!
#2
02/19/2008 (11:23 am)
If your heightmap is black and white, like it should be, then you have 0 to 255 in terms of the color of the specific pixel the player is "on" in the heightmap. So grab the players X and Y in the world, translate that to an X and Y position on the heightmap, at that X and Y grab the color of that pixel. (it'll be between 0 and 255, and I believe if it's black and white the R G and B values will all be the same like all 0 or all 25, etc.) Now you have this height value for your player according to the heightmap. However I'm not sure how the terrain editor generates the actual world height based on the heightmap, so you will have to take this value and probably multiply it by whatever value the terrain editor does to generate terrain to get your world height for the player. Try just using the value from the heightmap and see what happens, I don't remember if black is lowest or highest, probably lowest as it's RGB value is 0,0,0. I'm not familiar enough with Torque stuff to completely answer your question but try the Programming section, and this should give you an idea of what you should be trying to do.
Derrick Austin