Accessing terrain data
by Doug Pibal · in Torque Game Engine · 04/11/2006 (12:34 pm) · 7 replies
I want to place objects, while the program is running, at specific heights above the terrain surface, so I need some way to access the height of the terrain itself. Given any (x,y) coordinates, is there a way to use Torque Script to determine the z-coordinate of the terrain surface at that location? (Then I could just add the height of the object to that z-coordinate and place the object.) Thanks.
About the author
#2
function GroundHeight (%x, %y)
{
%start = %x SPC %y SPC "5000";
%end = %x SPC %y SPC "-1";
%ground = containerRayCast(%start, %end, $TypeMasks::TerrainObjectType, 0);
%z = getWord(%ground, 3);
return %z;
}
04/13/2006 (3:37 pm)
I made this function, but it always returns 0. I tested with echo(%ground) inside the function, and it always printed 0. Please help. Thanks.function GroundHeight (%x, %y)
{
%start = %x SPC %y SPC "5000";
%end = %x SPC %y SPC "-1";
%ground = containerRayCast(%start, %end, $TypeMasks::TerrainObjectType, 0);
%z = getWord(%ground, 3);
return %z;
}
#3
i suspect it will only work on the server,
unless you modify the implementation of containerRayCast.
04/13/2006 (4:02 pm)
Are you calling the function on server or client ?i suspect it will only work on the server,
unless you modify the implementation of containerRayCast.
#4
If you want to use it on a client, and it doesn't work, you could call it with a command to server.
04/13/2006 (4:13 pm)
It works perfectly fine for me if I put it in the server folfer and run as a server.If you want to use it on a client, and it doesn't work, you could call it with a command to server.
#5
04/13/2006 (4:15 pm)
Uh.... use getWord(...,2)
#6
04/17/2006 (1:55 pm)
I figured out that the function works, but I was calling it after the server was created, but before the mission was loaded. That is, before the terrain was loaded.
#7
%height = GetTerrainHeight(%pos);
I've never tried it but it sure sounds like what you want.
05/08/2006 (9:05 am)
Torque Script has a function:%height = GetTerrainHeight(%pos);
I've never tried it but it sure sounds like what you want.
Torque Owner Owen Ortmayer