yurembo Posted 9 hours ago Posted 9 hours ago 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 3 hours ago Posted 3 hours ago 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.
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.