I have a rather complicated problem that I can't get my head around. Maybe one of you can help.
Ok, I am working on a 3D racing game in GM8 that borrows techniques from JMike's city rendering example and Percsich.hu's car and terrain example. It features terrain created from heightmap coordinates and GM tiles can be mapped onto the terrain. First, the engine reads the 128x128 heightmap and then stores it into 16x16 cells in a 2048x2048 (same size as the room) ds_grid. Then the tile scanner reads all of the 16x16 tiles that are in the room and upscales them to 256x256 and then maps them onto the terrain (hope your still with me).
This all works fine but I can't seem to make the cameras z value move on the terrain's z value. I am using a modified version of Percsich.hu's "find_height" script from his car and terrain example to get the z from the heightmap but I am having trouble because the heightmap image is 128x128, the heightmap ds_grid is 2048x2048 and because everything gets scaled up 16 times in the room the camera is moving around in a room that is 32768x32768!
I've tried different combinations and all I get is every so often the camera jumps up to about 100 z and then comes back down to 0 z.
get_heightmap_z script:
var tempx, tempy, output, x_offset, y_offset, z1, z2, z3, z4;
tempx = argument0;
tempy = argument1;
//determine which grid and where it is
x_grid = floor(tempx/256);
y_grid = floor(tempy/256);
x_offset = tempx-16*x_grid;
y_offset = tempy-16*y_grid;
//get the z values from the ds list
z1 = ds_grid_get(obj_tile_creator.heightmap_grid,x_grid,y_grid);
z2 = ds_grid_get(obj_tile_creator.heightmap_grid,x_grid+16,y_grid);
z3 = ds_grid_get(obj_tile_creator.heightmap_grid,x_grid+16,y_grid+16);
z4 = ds_grid_get(obj_tile_creator.heightmap_grid,x_grid,y_grid+16);
//pinpoint the final location
if ( x_offset > y_offset )
{
output = z1 - x_offset * (z1-z2) /16 - y_offset * (z2-z3) /16;
}
else
{
output = z1 - x_offset * (z4-z3) /16 - y_offset * (z1-z4) /16;
}
return(output);
If I'm not making any sense and you need more info, please let me know and I will provide the GMK file if needed.
Thanks to anyone who will help.











