Hmm, very odd.
And I’ve replicated your example program (more or less) in Python, and can confirm this odd behaviour.
For reference, my setup is as follows:
OS: Ubuntu 18.04.6
Python: 3.6.9
Panda: 1.10.12
This may be a bug in Panda’s collision-detection–it might thus be worth your posting an issue for it, along with the relevant code, in the issue-tracker.
In case it helps, here is a trimmed-and-cleaned version of my Python implementation of the example code given above:
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Vec3, CollisionSphere, CollisionHandlerEvent, CollisionTraverser, CollisionNode, CollisionPolygon, CollisionCapsule
from direct.gui.DirectGui import *
from panda3d import __version__ as pandaVersion
print (pandaVersion)
import sys
print (sys.version)
class Game(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.cTrav = CollisionTraverser()
self.handler = CollisionHandlerEvent()
self.handler.addInPattern("collision")
self.accept("collision", self.bulletCollides)
plane = CollisionPolygon(Vec3(-3, 15, -6), Vec3(3, 15, -6),
Vec3(3, 15, -1), Vec3(-3, 15, -1))
wall = CollisionNode("poly")
wall.addSolid(plane)
wall.setIntoCollideMask(1)
wall.setFromCollideMask(0)
wallNP = render.attachNewNode(wall)
wallNP.show()
collider = CollisionNode("sphere")
shape = CollisionSphere(0, 0, 0, 0.5)
collider.addSolid(shape)
collider.setIntoCollideMask(0)
collider.setFromCollideMask(1)
collisionNP = render.attachNewNode(collider)
collisionNP.setPos(-1, 15, 1.1)
collisionNP.show()
self.cTrav.addCollider(collisionNP, self.handler)
collider = CollisionNode("capsule")
shape = CollisionCapsule(-0.5, 0, 0, 0.5, 0, 0, 0.5)
collider.addSolid(shape)
collider.setIntoCollideMask(0)
collider.setFromCollideMask(1)
collisionNP = render.attachNewNode(collider)
collisionNP.setPos(1, 15, 10.1)
collisionNP.show()
self.cTrav.addCollider(collisionNP, self.handler)
self.mew = collisionNP
render.setShaderAuto()
self.updateTask = self.taskMgr.add(self.update, "update task")
def bulletCollides(self, entry):
print ("COLLISION!", entry)
def update(self, task):
dt = self.clock.getDt()
self.mew.setZ(self.mew, -dt)
return task.cont
app = Game()
app.run()
I’m using a CollisionHandlerEvent there simply because I already had one set up in my test-code. It makes little difference, I daresay.
Note too that I’ve arranged for the capsule to start at a higher z-coordinate, and to then slowly descend. This demonstrates that the issue isn’t present for all positions, but does occur well beyond the edge of the CollisionPolygon.