TerrainBlock getHeight(x,y)
by Norv Brooks · in Torque Game Engine · 08/02/2006 (2:40 pm) · 4 replies
I've been able to create wildfire/smoke particleEmitter objects and move them dynamically, but I want to set the "z" coordinate to the elevation (height) of the terrain at the particleEmitter's location. I've tried to use the "getHeight(x,y) method in the "terrainBlock" but I can't get the method to be recognized. Here's the code where I'm trying to do it. This code is located in "levelLoader.cs".
I've also tried
Anybody see what I'm missing? Or am I trying to do something that can't be done?
Also, I was wondering, since Player objects' movement seem to adjust to the terrain handled by the engine. Would it be more efficient to create invisible players and mount the particle emitters on them and let the engine handle the changes in terrain elevation?
Thanks,
Norv
// 2a
case GROUNDFIREHEAD:
echo("\c2 Loading GROUNDFIRE");
%block = new ParticleEmitterNode(GroundfireEmitterHead) {
position = "-132.677 -102.417 63.663";
rotation = "1 0 0 0";
scale = "1 1 0.5";
dataBlock = "GroundfireParticleEmitterNode";
emitter = "GroundfireEmitter";
velocity = "1";
fireType = 0; //HEAD
};
%elevation = [b]TerrainBlock::getHeight(-132.677,-102.417);[/b]
%curPos = %block.getTransform();
setWord(%curPos,2,%elevation);
%block.setTransform(%curPos);
echo("Position = ",%block.getTransform());
wildfireGroup.add(%block);I've also tried
terrain.getHeight(-132.677,-102.417);and just plain
getHeight(-132.677,-102.417);
Anybody see what I'm missing? Or am I trying to do something that can't be done?
Also, I was wondering, since Player objects' movement seem to adjust to the terrain handled by the engine. Would it be more efficient to create invisible players and mount the particle emitters on them and let the engine handle the changes in terrain elevation?
Thanks,
Norv
About the author
#2
Thanks for the help. I did do a search for different words & phrases, but obviously not "terrain height".
Norv
08/02/2006 (3:42 pm)
Peter - thanks! That works. A person can get misled if familiar with C++. You have to make sure you put the arguments in quotes with no comma between the x & y. See belowgetTerrainHeight("-100 -100");Thanks for the help. I did do a search for different words & phrases, but obviously not "terrain height".
Norv
#3
08/03/2006 (8:30 am)
Just felt like posting this....this will give spawn points a little bit of radius.function getGoodBotSpawnPoint(%basePoint) {
%theZ = -1;
%terrainLocation = 1;
%tCount = 0;
//keep getting an XY location until the terrainLocation for that XY location is above the terrain.
while (%terrainLocation > %theZ) { //terrainZ is above the Z we got
if (%tCount == 20) {
//if it takes too long, get out & just return the default spawn
echo("break due to no point found");
%theSpawnPoint = %basePoint;
break;
}
%theSpawnPoint = TransformVectorAdd(%basePoint,randomVector(25, false));
%theXY = getWords(%theSpawnPoint, 0, 1);
%theZ = getWord(%theSpawnPoint, 2);
//echo("z=" @ %theZ @ "; xy=" @ %theXY);
%terrainLocation = getTerrainHeight(%theXY);
//echo("terrain=" @ %terrainLocation);
%tCount++;
}
return %theSpawnPoint;
}
//just adds a vector to a transform
function TransformVectorAdd(%theTransform, %addToVector) {
%transVector = getWords(%theTransform, 0, 2);
%addedVector = VectorAdd(%transVector, %addToVector);
return %addedVector SPC getWords(%theTransform, 3);
}
// -> just creates a random vector XY vector (or XYZ if %bIncludeZAxis is true), using %maxNum as
// the max value for each coordinate.
function randomVector(%maxNum, %bIncludeZAxis) {
%newXmult = getRandom(1); //0 or 1
%newYmult = getRandom(1);
%newZmult = getRandom(1);
//if multiplier was 0, then make it negative, so we can either have -1 or +1 multipliers
%newXmult -= (%newXmult == 0 ? 1:0);
%newYmult -= (%newYmult == 0 ? 1:0);
%newZmult -= (%newZmult == 0 ? 1:0);
if (!%bIncludeZAxis)
%newZmult = 0;
%newX = (getRandom() * %maxNum) * %newXmult;
%newY = (getRandom() * %maxNum) * %newYmult;
%newZ = (getRandom() * %maxNum) * %newZmult;
return %newX SPC %newY SPC %newZ;
}
#4
Thanks.
08/03/2006 (9:50 am)
Juan - thanks for the post. For my purpose, I want more control of the spawn point; however, someone else may be looking for your code.Thanks.
Torque 3D Owner Peter Simard
Default Studio Name