StOneDOes Posted January 22, 2023 Share Posted January 22, 2023 I'm wondering what the correct set of properties/functions are to apply in order to get a player like model to move around the map on my terrain. I assume that first I need to set something that will snap the model to the terrain, and then when it moves I want it to follow the terrain height in a realistic manner - I can do this manually but I assume that it is built it? I'm guessing that I may need a navmesh but haven't really looked into that yet. At this stage I just have a model that I have added an Actor to with a Mover, but that's all. Quote Link to comment Share on other sites More sharing options...
SpiderPig Posted January 22, 2023 Share Posted January 22, 2023 You should use the PHYSICS_PLAYER option. There is an example here. https://www.ultraengine.com/learn/Entity_SetInput?lang=cpp Quote Link to comment Share on other sites More sharing options...
Josh Posted January 22, 2023 Share Posted January 22, 2023 For an RTS, you may want to use a navigation mesh: https://www.ultraengine.com/learn/CreateNavMesh?lang=cpp This will also handle large crowds. 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...
StOneDOes Posted January 22, 2023 Author Share Posted January 22, 2023 59 minutes ago, Josh said: For an RTS, you may want to use a navigation mesh: https://www.ultraengine.com/learn/CreateNavMesh?lang=cpp This will also handle large crowds. Thanks for this. However I'm not able to get it to work at this point. I'm assuming I've got something wrong in CreateNavMesh(). I created a minimal example by basically sticking the terrain sample and navmesh sample together, but can't get that to work either: #include "UltraEngine.h" #include "ComponentSystem.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the display list auto displays = GetDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR); //Create a world auto world = CreateWorld(); world->SetAmbientLight(0); //Create a framebuffer auto framebuffer = CreateFramebuffer(window); //Create a camera auto camera = CreateCamera(world); camera->SetFov(70); camera->SetPosition(0, 50, 0); camera->SetRotation(45, 0, 0); camera->SetClearColor(0.125); //Sunlight auto light = CreateDirectionalLight(world); light->SetRotation(45, 35, 0); light->SetColor(2); //Create terrain auto terrain = CreateTerrain(world, 512); terrain->LoadHeightmap("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Terrain/512.r16"); terrain->SetScale(1, 100, 1); //Create base material auto ground = CreateMaterial(); auto diffusemap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/river_small_rocks_diff_4k.dds"); auto normalmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/river_small_rocks_nor_gl_4k.dds"); ground->SetTexture(diffusemap, TEXTURE_DIFFUSE); ground->SetTexture(normalmap, TEXTURE_NORMAL); terrain->SetMaterial(ground); //Create paint material auto rocks = CreateMaterial(); diffusemap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k.dds"); normalmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k_dot3.dds"); auto dispmap = LoadTexture("https://raw.githubusercontent.com/UltraEngine/Documentation/master/Assets/Materials/Ground/Rocks_Dirt_Ground_2k_disp.dds"); rocks->SetTexture(diffusemap, TEXTURE_DIFFUSE); rocks->SetTexture(normalmap, TEXTURE_NORMAL); rocks->SetTexture(dispmap, TEXTURE_DISPLACEMENT); //Apply material based on terrain slope for (int x = 0; x < terrain->resolution.x; ++x) { for (int y = 0; y < terrain->resolution.y; ++y) { float slope = terrain->GetSlope(x, y); if (slope > 15.0f) { float wt = Min((slope - 15.0f) / 10.0f, 1.0f); terrain->SetMaterial(x, y, rocks, wt); } } } //Camera controls auto actor = CreateActor(camera); actor->AddComponent<CameraControls>(); //Create navmesh auto navmesh = CreateNavMesh(world, 512, 512, 512, 8, 8); navmesh->Build(); //Create player auto player = CreateCylinder(world, 0.4, 1.8); player->SetColor(0, 0, 1); player->SetPosition( 0.f, 50.f, 0.5 ); player->SetScale( 10.f, 10.f, 10.f ); auto agent = CreateNavAgent(navmesh); player->Attach(agent); //Main loop while (window->Closed() == false and window->KeyDown(KEY_ESCAPE) == false) { if (window->MouseHit(MOUSE_LEFT)) { auto mousepos = window->GetMousePosition(); auto rayinfo = camera->Pick(framebuffer, mousepos.x, mousepos.y); if (rayinfo.success) { agent->Navigate(rayinfo.position); } } world->Update(); world->Render(framebuffer); } return 0; } Quote Link to comment Share on other sites More sharing options...
Josh Posted January 22, 2023 Share Posted January 22, 2023 Navmesh generation is working: Still testing this... 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...
Solution Josh Posted January 22, 2023 Solution Share Posted January 22, 2023 Here you go: //Create navmesh auto navmesh = CreateNavMesh(world, 512, 512, 512, 8, 8); //navmesh->SetDebugging(true);// visualize navmesh geometry navmesh->Build(); //Create player auto player = CreateCylinder(world, 0.4, 1.8); player->SetNavigationMode(false);// prevent player from triggering navmesh update player->SetColor(0, 0, 1); player->SetScale(10.f, 10.f, 10.f); auto agent = CreateNavAgent(navmesh); agent->SetPosition(0.f, 50.f, 0.5); player->Attach(agent); 1 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...
StOneDOes Posted January 22, 2023 Author Share Posted January 22, 2023 Legendary, thank you! Although can you please check the speed if you don't mind? I tried SetMaxSpeed() and SetMaxAcceleration() as values all the way up to 5000 but couldn't get the object to move any faster. Quote Link to comment Share on other sites More sharing options...
Josh Posted January 22, 2023 Share Posted January 22, 2023 You're right, those values won't get set unless the agent has already been initialized by calling the Navigate() method. I fixed this for the next build. In the meantime you can just call these methods after a call to Agent::Navigate(). Be careful with the max acceleration value. I set both to 1000 and the agent started rubber-banding comically. 1 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...
Josh Posted January 22, 2023 Share Posted January 22, 2023 BTW, your scale for this scene is far too big. I recommend using real-world units, where one meter = one unit space. Otherwise you may encounter unexpected problems. At the very least it will make your art pipeline problematic, because all your loaded models will need to be rescaled. 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...
StOneDOes Posted January 23, 2023 Author Share Posted January 23, 2023 19 hours ago, Josh said: BTW, your scale for this scene is far too big. I recommend using real-world units, where one meter = one unit space. Otherwise you may encounter unexpected problems. At the very least it will make your art pipeline problematic, because all your loaded models will need to be rescaled. No stress here - this is just purely for me to learn how to use the fundamentals of the engine; the objects will not be the size of that cylinder ... much smaller . I have some artwork that was created for Leadwerks some years ago so I'm going to start with that and see how it goes. Quote Link to comment Share on other sites More sharing options...
StOneDOes Posted January 23, 2023 Author Share Posted January 23, 2023 This is a little bit closer to what it will look like in terms of scale. The NavAgent class could use a few more controlling functions eg. set how much rotation must be involved to turn the object around before moving in that direction. I could drop some thoughts and feedback into the suggestion box, but I assume you already have this kind of stuff in mind @Josh? Quote Link to comment Share on other sites More sharing options...
Josh Posted January 23, 2023 Share Posted January 23, 2023 Wow, I don't know why but it already looks like a game. I don't know how you guys do it. 😄 Please create a thread in the suggestions forum for any additional ideas you have! 1 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...
StOneDOes Posted January 23, 2023 Author Share Posted January 23, 2023 5 minutes ago, Josh said: Wow, I don't know why but it already looks like a game. I don't know how you guys do it. 😄 Please create a thread in the suggestions forum for any additional ideas you have! Its a reflection of your great work! The engine API is so intuitive; I'm having quite an easy time building my game framework around it. And sure, will do. 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.