❄️🎁⛄ The Winter Games Tournament is Live! 🎄🎅❄️
Jump to content

Why NavAgent:Navigate always return false?


Recommended Posts

Posted

It looks like creating a NavMesh doesn't require much code. First, create the NavMesh in the editor, then write the following code:

--First, Zombie_Head:Load is called, then Zombie_Head:Start
function Zombie_Head:Start()
    zombie = Model(self)
    zombie:Animate("idle")
	
	if self.navmesh then
        self.agent = CreateNavAgent(self.navmesh, 0.5, 0.5)
        self.agent:SetPosition(self:GetPosition(true))
        self.agent:SetRotation(self:GetRotation(true).y)
        self:SetPosition(0, 0, 0)
        self:Attach(self.agent)
		self.navmesh:SetDebugging(true)
    end
end

function Zombie_Head:Load(properties, binstream, scene, flags, extra)
    self.navmesh = nil
    if #scene.navmeshes > 0 then
        self.navmesh = scene.navmeshes[self.navmeshindex]
    end
    
    return true
end

then you should call NavAgent:Navigate like so:

-- to move a Zombie to a main character's position after a mouse click
function Zombie_Head:Update()
	if window:MouseHit(MOUSE_LEFT) then    
      p1 = self.agent:GetPosition(true)
      p2 = self:GetPosition(true)
      --window.text = tostring(p1.x) .. " | " .. tostring(p1.y) .. " | " .. tostring(p1.z)
      window.text = tostring(self.agent:Navigate(p1))
      self.agent:SetMaxSpeed(2)
    end
end

But self.agent:Navigate(p1) always returns false and a character doesn't move.

Posted

It probably means that there is no path to the point you are trying to reach. There are some additional parameters for the function that let you 

There are two optional paramters I need to add to the docs that give more control:
virtual bool Navigate(const dFloat x, const dFloat y, const dFloat z, const int maxsteps = 100, const float maxdistance = 1.0f);

However, the default values for these arguments usually provide good results. This suggests that you are trying to navigate to a position that cannot be reached because something is blocking it, so the closest point on the navmesh to your destination is greater than maxdistance.

Let's build cool stuff and have fun. :)

Posted

This is very strange.

Perhaps objects representing the ground should have some special properties or object types?

In the example The Ferst-Person Shooter, all floor objects have the following properties: Static = True; Nav Obstacle = true;

But if I assign “Nav Obstacle = true;” to my NPCs, they slowly fall through the ground.

Maybe there are some special parameters to Nav Mesh?

 

My character and an enemy are very closed. Nav mesh is stretched across the entire game world, as in the example The First-Person Shooter.

When I rebuild the navigation (Shift + N) in the editor the surfaces of game objects are not colored blue as in the example The First-Person Shooter.

image.thumb.png.55ad224ab56af4d9588e51e64d21a45c.png

Posted

I deleted NavMesh then create it again and all surfaces in my level are colored in blue.

image.thumb.png.44057d602ddcae6b467c5011ea562d48.png

But Agen:Navigate returns false.

Another point. At the beginning of the game, the characters are slightly elevated above the ground, so when the game starts, they fall to the ground. But after the NavMesh is created, the zombie falls to the ground very slowly. Early I used to think this was because "Nav Obstacle = true"; turns out not.

The surface needs to have its "Nav Obstacle = true" parameter set to make it blue.

Posted

I played with Nav Mesh parameters and sometimes got: self.agent:Navigate(p1) == true but a zombie didn't move

image.png.afaa842530f7e85295efba5504d21c20.png

This is parameters values from The First-Person Shooter example.

Posted
5 hours ago, yurembo said:

But if I assign “Nav Obstacle = true;” to my NPCs, they slowly fall through the ground.

You don't want your characters to act as a navigation obstacle. That will make their volume get removed from the navigation mesh, and may be the cause of your problem. Navigtion agents will avoid each other using the built-in crowd system.

  • Like 1

Let's build cool stuff and have fun. :)

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.

×
×
  • Create New...