Slimwaffle Posted August 11, 2018 Share Posted August 11, 2018 I have two scripts for AI. Doesn't matter which I use I get the same problem with both. No matter how low I set the sight range and hearing range enemies will target me anywhere on the map and move towards me no matter the distance. Here is the script I have mainly been using. HUD AI.lua Quote Link to comment Share on other sites More sharing options...
havenphillip Posted August 11, 2018 Share Posted August 11, 2018 Are you using the minimap? Looks like it may be the minimap sphere. I deleted it and they worked normally. 1 Quote Link to comment Share on other sites More sharing options...
Slimwaffle Posted August 11, 2018 Author Share Posted August 11, 2018 hmm interesting. I will look into it. I am hoping to keep the minimap. Its a really nice feature. I may have to change the way enemies spawn in then if I can't fix this. Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 12, 2018 Share Posted August 12, 2018 If the minimap you are referring to was the simple shader and script version I posted and then Aggror added a sphere to it to check for nearby enemies, then the problem could be that the sphere is being set as a child to the player. Twice for some reason? If i had to guess what the problem was without testing it out, i would say its because the sphere is now a child of the player which the enemy AI script assumes the sphere is the player. The sphere is 50 meters in diameter. function Script:Start() self.miniMapSphere = Model:Sphere(8,self.player) -- by putting the player as the second parameter, you just set the sphere as a child to the player self.miniMapSphere:SetScale(50,50,50) self.miniMapSphere:SetPosition(self.player:GetPosition(true)) --Parenting the sphere to the player, means we dont have to update the position ourselves again. self.miniMapSphere:SetParent(self.player) -- this is duplicating setting the parent? self.miniMapSphere:Hide() end so what you can try is to remove the parenting and then update the position of the sphere in the Script:UpdateWorld() function. function Script:Start() self.miniMapSphere = Model:Sphere(8) self.miniMapSphere:SetScale(50,50,50) self.miniMapSphere:SetPosition(self.player:GetPosition(true)) self.miniMapSphere:Hide() end function Script:UpdateWorld() self.timer = self.timer + Time:GetSpeed() self.miniMapSphere:SetPosition(self.player:GetPosition(true)) --add this to update the position of the sphere if self.timer > self.timeUntilMinimapUpdates then self.timer = 0 self.enemyEntities = nil local AABB = self.miniMapSphere:GetAABB(1) --We pass along the entity that our current script is attached to world:ForEachEntityInAABBDo(AABB, "Callback", self.entity) end end If the above is not the latest and greatest code you are working from, then my apologies. This is just a guess since i don't have an easy way to test it out, but it may be worth a try to see if it resolves your issue. --EDIT: I just tested my theory above by placing a crawler with the standard monster AI script into a simple terrain scene in the editor. I changed the visual range to 5 meters. i then placed a player prefab in the scene about 30 meters away. Then I created a 50-m diameter CSG sphere with the invisible material. Placed the sphere's center at the location of the player and dragged the sphere in the scene browser to be a child under the player. Started the game and once the player moves a couple of steps toward the crawler, and it immediately starts to chase me. So it looks like my theory may be correct. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
havenphillip Posted August 12, 2018 Share Posted August 12, 2018 Yeah that works. The sightrange is still off. I have to set it to -22 to walk up to the crawler. Should be at 0. Is there a way to compensate for that in the minimap script? Like add something to the table? Quote Link to comment Share on other sites More sharing options...
macklebee Posted August 12, 2018 Share Posted August 12, 2018 Again, I can't speak for what you have because I do not have it. If you are using the standard monster AI script on the crawler, then it should work correctly just like the test that I did above. If you are using your own custom scripts for the AI and whatever you currently have for the minimap, then nobody but you probably has that exact setup. Provide an example project that shows the issue and someone may be willing to help troubleshoot. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
havenphillip Posted August 12, 2018 Share Posted August 12, 2018 Ok so I added this line in the HUD AI under ChooseTarget(): if d < self.sightradius then ..so it looks like this: function Script:ChooseTarget() local entities = GetEntityNeighbors(self.entity,self.sightradius,true) local k,entity for k,entity in pairs(entities) do if entity.script.teamid~=nil and entity.script.teamid~=0 and entity.script.teamid~=self.teamid then if entity.script.health>0 then local d = self.entity:GetDistance(entity) local pickinfo=PickInfo() if self.entity.world:Pick(self.entity:GetPosition()+Vec3(0,1.6,0),entity:GetPosition()+Vec3(0,1.6,0),pickinfo,0,false,Collision.LineOfSight)==false then if d < self.sightradius then --added so they don't charge from any distance return entity.script end end end end end end Not sure why that's not in the original script. So to OP just what Macklebee suggested above, plus change this one line in your HUD AI script, save it as a prefab if you're spawning them, and also I have to change this line in the minimap script from a 1 to a 2 for the dots to appear: local AABB = self.miniMapSphere:GetAABB(1) ...so it looks like: local AABB = self.miniMapSphere:GetAABB(2) Quote Link to comment Share on other sites More sharing options...
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.