Sight of AI..

Hello everyone.

I’m working on AI.
So I starts with ‘walking dodge the wall’ sample.

I have 1 ralph with his sight represent to “collision polygon”.
like a text image below.

… _______________
… \ …/
… /
…\ … /
…\ …/
…/
…/
…/
…RALPH

The problem is the collision polygon can not detect the .egg file.
(I think it can only detect to collision solid.)
my code is below.

self.environ = loader.loadModel("models/map.egg")      
self.environ.reparentTo(render)
self.environ.setCollideMask(BitMask32.bit(1)) 

self.CollidPolygon = CollisionPolygon(.....)
self.ColNode.addSolid(self.CollidPolygon)
self.ColNode.setFromCollideMask(BitMask32.bit(1))
self.ColNode.setIntoCollideMask(BitMask32.bit(1))
self.ColNodeNP = self.ralph.attachNewNode(self.ColNode)
self.cTrav.addCollider(self.ColNodeNP, self.HandlerQueue)
self.ColNodeNP.show()

#--------------- IN Task ----------------------
self.cTrav.traverse(render)
entries = []
for i in range(self.HandlerQueue.getNumEntries()):
       entry = self.HandlerQueue.getEntry(i)
       entries.append(entry)
if (len(entries)>0) and (entries[0].getIntoNode().getName() == 'wall'):
       self.ralph.setH(self.ralph.getH() - elapsed*300)
       print 'hello'

It isn’t print ‘hello’ when the ralph walk through the wall.
Any Idea or another idea to do this??

Thank you.

Well, I see two possible issues:

  1. First, have you given the wall any collision geometry? If not (which seems to be the case), I see two primary solutions:
    a) The first, and, I think, better, is to give the wall some collision geometry; how this is done depends, I believe, on how which program you use to make your environment models and how you export to .egg - what do you use?
    b) The second, and rather less efficient, I believe, is to just have your viewing polygon collide with visible geometry, although I’m confident that this will incur problem number two, below.

  2. Second, are you sure that Ralph doesn’t have any collision geometry? If he does, you may find that you have an entry for the collision between him and your polygon.

Two final notes (this post seems to deal in twos ^^; ):

  1. While Roaming Ralph does it, I think, I’m pretty sure that you can do without the copying of the contents of the collision queue to a new list - you should be able to just use getEntry, I believe.

  2. You don’t appear to be sorting your entries, meaning that their order is not, to the best of my knowledge, guaranteed. The appropriate call is just <my_queue>.sortEntries(), which sorts from nearest to furthest.

To be honest, I think that this element of Roaming Ralph should perhaps be updated, unless it has already been changed for 1.5.3…

Also, let me point out that you are adding a CollisionPolygon to a traverser as a “from” object, which is not supported. (The collision system would have complained if there had actually been any other polygons for Ralph’s view triangle to collide against.)

As per the manual, the only collision types which work as “from” objects are sphere, ray, segment, and line.

David

Thank you very much for your advise.

I used 3DsMax and export to “pose” type (from ‘model’,‘anim’,‘both’ and ‘pose’).

I tried the collision sphere instead ,it’s work very well.

Thanks for this helpful note. :stuck_out_tongue:

And I saw some error like this on console (but the program was not terminate.)

:collide(error): Invalid attempt to detect collision from CollisionPolygon!

This means that a CollisionPolygon object was added to a
CollisionTraverser as if it were a colliding object.  However,
no implementation for this kind of object has yet been defined
to collide with other objects.

Like David said. It’s not support ‘From’.
So I will try another colission.
Thanks again.!