ErhanK Posted February 28, 2019 Share Posted February 28, 2019 Hi. I want to load the player entity position from an object in the editor. It works very well but; I want to spawn in the center of the scene when there is no object named "info_player_start". When I remove the comment lines, it always spawns at the center of the scene. I don't understand why. Here is my code... #include "Game.h" Game::Game() { loadMap(); loadEntities(); player = new Player(playerStartPosition); } Game::~Game() { delete player; } void Game::loadMap() { std::string mapname = System::GetProperty("map", "Maps/start.map"); if (!Map::Load(mapname)) Debug::Error("Failed to load map \"" + mapname + "\"."); } void Game::loadEntities() { for (const auto e : World::GetCurrent()->entities) { if (e->GetKeyValue("name") == "info_player_start") { playerStartPosition = e->GetPosition(); } /*else { playerStartPosition = Vec3(0.0f, 0.0f, 0.0f); }*/ } } void Game::Update() { player->Update(); } Quote Link to comment Share on other sites More sharing options...
Josh Posted March 1, 2019 Share Posted March 1, 2019 Do this: void Game::loadEntities() { playerStartPosition = Vec3(0.0f, 0.0f, 0.0f); for (const auto e : World::GetCurrent()->entities) { if (e->GetKeyValue("name") == "info_player_start") { playerStartPosition = e->GetPosition(); break; } } } And please make sure you understand why this works! Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
ErhanK Posted March 1, 2019 Author Share Posted March 1, 2019 Of course! Thanks. Because this is a loop and the last element in the list is not "info_player_start". understood :) I should practice more. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.