Jump to content

NavMesh wont work correct if player starts not with pos 0,0,0


Andy90
 Share

Go to solution Solved by Josh,

Recommended Posts

This is why:

/// <summary>
/// Setup the Controller
/// </summary>
void MouseMovementController::Start() {
    auto entity = GetEntity();
    entity->AddTag("player");
    /// ToDo remove when nav mesh bug is fixed
    entity->SetPosition(0, 0, 0);
    entity->SetRotation(0, 180, 0);
    ///

With the SetPosition command commented out, I can now produce the error...

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

The behavior is definitely doing something strange. I am going to try getting rid of the player and just creating a simple nav agent in the main code file...

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

  • Solution

This is what you need at the bottom of MouseMovementController::Start:

///Create a new NavAgent for the player character
this->agent = CreateNavAgent(this->nav_mesh);
this->agent->SetPosition(entity->GetPosition(true));
entity->SetPosition(0, 0, 0);
entity->SetRotation(0, 0, 0);
entity->Attach(agent);

The player's position and rotation are retained as the local offset and rotation when it is attached to the navagent. This allows you to set an offset, or reverse the orientation of the player. However, as we have seen, this can be confusing and cause unintended consequences, so maybe the command should include an optional offset position and rotation instead.

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

Its working. Thanks. Maybe an example within the documentation would be nice. So other ppl wont have this issue. 

This is the current code from Ultra Engine - Best game engine for VR optimized for fastest virtual reality 3D performance

#include "UltraEngine.h"

using namespace UltraEngine;

int main(int argc, const char* argv[])
{
    //Get the displays
    auto displays = GetDisplays();

    //Create a window
    auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0], WINDOW_CENTER | WINDOW_TITLEBAR);

    //Create a framebuffer
    auto framebuffer = CreateFramebuffer(window);

    //Create a world
    auto world = CreateWorld();

    //Create a camera    
    auto camera = CreateCamera(world);
    camera->SetFov(70);
    camera->SetClearColor(0.125);
    camera->SetPosition(0, 3, -6);
    camera->SetRotation(35,0,0);

    //Create light
    auto light = CreateBoxLight(world);
    light->SetRange(-20, 20);
    light->SetArea(20, 20);
    light->SetRotation(35, 35, 0);
    light->SetColor(3);

    //Create scene
    auto ground = CreateBox(world, 10, 1, 10);
    ground->SetPosition(0, -0.5, 0);
    ground->SetColor(0, 1, 0);
    auto wall = CreateBox(world, 1, 2, 4);

    //Create navmesh
    auto navmesh = CreateNavMesh(world, 10, 5, 10, 4, 4);
    navmesh->Build();

    //Create player
    auto player = CreateCylinder(world, 0.4, 1.8);
    player->SetNavObstacle(false);
    player->SetColor(0, 0, 1);
    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;
}

 

  • Like 1
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...