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

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. :)

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...