yurembo Posted yesterday at 02:00 PM Posted yesterday at 02:00 PM 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. Quote
Josh Posted yesterday at 07:51 PM Posted yesterday at 07:51 PM 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. Quote Let's build cool stuff and have fun.
yurembo Posted 8 hours ago Author Posted 8 hours ago 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. Quote
yurembo Posted 6 hours ago Author Posted 6 hours ago I deleted NavMesh then create it again and all surfaces in my level are colored in blue. 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. Quote
yurembo Posted 3 hours ago Author Posted 3 hours ago I played with Nav Mesh parameters and sometimes got: self.agent:Navigate(p1) == true but a zombie didn't move This is parameters values from The First-Person Shooter example. Quote
Josh Posted 2 hours ago Posted 2 hours ago 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. 1 Quote Let's build cool stuff and have fun.
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.