Hello,
I’m trying to write code that finds a random spot on terrain(especially procedual). It works but not fully. I just want to know if I’m doing it accurately. I don’t think its accurately picking up the Terrain Y(y-up / normal location). So, it’s not always accurate when placing the Pod.
Future updates would test for collision and probably place objects from vegetation to building structures. Hopefully through weightmaps or rule system.
Vivienne
[code] ///testing
Vector3 characterPosition = characternode_ -> GetPosition();
bool levelarea=false;
int randomSpotx;
int randomSpotz;
for(int i=0; i<1000; i++)
{
randomSpotx=rand()%256;
randomSpotz=rand()%256;
randomSpotx-=128;
randomSpotz-=128;
/// Select a position
Vector3 selectPosition=Vector3(characterPosition.x_+randomSpotx,terrain->GetHeight(Vector3(characterPosition.x_,characterPosition.y_)),characterPosition.z_+randomSpotz);
float average_y=(
terrain->GetHeight(Vector3(selectPosition.x_+(podSize.x_/2),selectPosition.z_+(podSize.z_/2)))+
terrain->GetHeight(Vector3(selectPosition.x_+(podSize.x_/2),selectPosition.z_-(podSize.z_/2)))+
terrain->GetHeight(Vector3(selectPosition.x_-(podSize.x_/2),selectPosition.z_+(podSize.z_/2)))+
terrain->GetHeight(Vector3(selectPosition.x_-(podSize.x_/2),selectPosition.z_-(podSize.z_/2))))/4;
if((fabs(selectPosition.y_/average_y)<0.995f)||(fabs(selectPosition.y_/average_y)>1.005f))
{
//
}
else
{
levelarea=true;
randomSpotx=characterPosition.x_+randomSpotx;
randomSpotz=characterPosition.z_+randomSpotz;
break;
}
}
/// After the For loop either a spot was found our not
if(levelarea)
{
/// Change position of the box by using the Bounding Box and terrain information
position2.y_ = terrain->GetHeight(Vector3(randomSpotx,randomSpotz));
BoundingBox podmodelbox = PodObject1 ->GetBoundingBox();
Vector3 podSize=podmodelbox.Size();
PodNode1->SetPosition(Vector3(randomSpotx,position2.y_+(podSize.y_/2)+.3,randomSpotz));
Print ("Spot Found");
}else
{
Print("No Spot Found");
}
[/code]