Jump to content

Making the AI stop at a door and open it, not fly through it


PerEspen00
 Share

Recommended Posts

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

Link to comment
Share on other sites

Are you not able to check if they collide with the door? then stop them. I'd recommend keeping the 'pick' too... there's probably a quite simple way to make the pick alone detect the door every time, but I just woke up and I'm too lazy to think about the simple math involved... maybe later.

Link to comment
Share on other sites

I have closed doors in my game. The player will not go thru them as the door has a mass set to zero.

 

Im using a joint, which wont open/Close with the door if its 0. if i set it to >0 when its moving and otherwise keep it 0, they will fly through as soon as it starts opening.

 

Are you not able to check if they collide with the door? then stop them. I'd recommend keeping the 'pick' too... there's probably a quite simple way to make the pick alone detect the door every time, but I just woke up and I'm too lazy to think about the simple math involved... maybe later.

 

Actully, i redid the pick and now it works 100% of the time so far. Thanks, I'll return if I see them flying again

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...