Quick version: Looking for a way to make my AI check if there is a door infront of them, any suggestions appreciated.
Long version:
So, I've made a custom Ai script, which basically does a bunch of things. But, when the ai is chasing the player, with entity:follow. Everything works fine till i get to a door. If the door is closed the ai will fly through the door. So I made a pick operation to counter this. It didn't entierly work, code below:
if the mode is "chase" then this happens every frame
elseif self.AtkMode == "chase" then
if self.door == nil then -- where i store the door entity if one is found in the pick operation
-- System:Print("chasin")
if self:CheckForDoor() == nil then --the below code
self.entity:Follow(self.Target, self.Speed,self.Speed)
else
System:Print("door")
self.entity:Stop()
end
else
self.entity:Stop()
if self.door.Done == true then --door.Done = true when my sliding door has finished opening
self.door = nil
end
end
end
Gets called from the above code, this is the pick operation
function Script:CheckForDoor()
if((Time:GetCurrent() - self.TimeLastCheck)/1000 > self.TimeBtwChecks) then --basically every frame, not the problem
self.TimeLastCheck = Time:GetCurrent()
local pickinfo = PickInfo()
local a1 = Transform:Point(Vec3(0,150,0), self.entity, nil)
local a2 = Transform:Point(self.CheckOffsetC, self.entity, nil)
if self.entity.world:Pick(a1, a2, pickinfo, 0, true, Collision.Debris) then
System:Print("here1")
if pickinfo.entity.script ~= nil then
System:Print("here2")
if type(pickinfo.entity.script.Toggle) == "function" then
self.door = pickinfo.entity.script
if pickinfo.entity.script.DoorOpen == false then
pickinfo.entity.script:Toggle()
end
self.LastResultC = true
return true
--elseif pickinfo.entity.script.Live == ~= nil then
else
self.LastResultC = nil
end
else
self.LastResultC = nil
end
else
self.LastResultC = nil
end
else
return self.LastResultC
end
return self.LastResultC
end
This fixes it, sometimes, but sometimes the pick dosen't find the door or finds something else and then it flys through the door. So this is kinda a bug report bcs entites shouldn't be flying through walls, and a question if there is any way to make this more effecient(and make it work). Got around 6 ai's in my scene.
The door has 1 mass, navobstacle disabled, scene collision. Uses a slider joint to open.
Similer post but no answer(or they said pick operation which i tried):
http://www.leadwerks.com/werkspace/topic/14318-my-monsters-can-run-through-walls/
Another question: sometimes when the ai is chasing me it will stop and start spinning around in a cirkel, this usally happens when i go through a door. They will stop on the other side even though its open and start spinning, as if the path through the open door dosen't exist. This could be a problem with them finding the door or something while its open