For some reasons the terrain elevation returns allways 0. Im not sure if its a bug or if i did something wrong.
void LootSpawner::SpawnLoot(shared_ptr<Terrain> terrain, shared_ptr<Map> scene, std::weak_ptr<Entity> player)
{
auto entity = GetEntity();
CreateDebugSpehere(entity->GetWorld(), scene, entity->position, Vec4(1.00, 0.07, 0.07, 1.0));
if (!prefabList.empty()) {
for (int i = 0; i < this->itemCount; i++) {
float degress = 360 / this->itemCount * i;
auto radians = Radians(degress);
auto distance = Random(diameterMin, diameterMax);
auto sin = Sin(degress);
auto cos = Cos(degress);
float x = entity->GetPosition(true).x + distance * cos;
float z = entity->GetPosition(true).z + distance * sin;
float y = terrain->GetElevation(x, z);
Print("Terrain height " + String(y));
int prefabIndex = Random(0, prefabList.size());
auto prefabName = prefabList[prefabIndex];
auto prefab = LoadPrefab(entity->GetWorld(), prefabName);
prefab->SetPosition(x, y, z);
auto lootCrate = prefab->GetComponent<LootCrate>();
lootCrate->SetPlayer(player);
scene->AddEntity(prefab);
CreateDebugSpehere(entity->GetWorld(), scene, Vec3(x, y, z));
}
}
this->spawned = true;
}
void LootSpawner::CreateDebugSpehere(shared_ptr<World> world, shared_ptr<Map> scene, Vec3 location, Vec4 color)
{
if (debug) {
auto sourceSphere = CreateSphere(world);
sourceSphere->SetColor(color);
sourceSphere->SetPosition(location);
scene->AddEntity(sourceSphere);
}
}
bool LootSpawner::Load(table& properties, shared_ptr<Stream> binstream, shared_ptr<Map> scene, const LoadFlags flags)
{
itemCount = properties["itemCount"];
prefabs = properties["prefabs"];
diameterMin = properties["diameterMin"];
diameterMax = properties["diameterMax"];
auto player = scene->GetEntity(properties["player"]);
prefabList = prefabs.Split(";");
for (auto entity : scene->entities) {
if (entity->As<Terrain>()) {
SpawnLoot(entity->As<Terrain>(), scene, player);
}
}
return true;
}