collisions (again...)

I try to explain in other words:
I did a working sample, pretty similar yours, and the link where to download it in my post upwards - now you go there, download that sample, that includes the blender source as well, and try to see what is wrong in your script. That’s what I would say in my post above.

I just don getit hows that gonna help. Your model and collision model are the same file and the balls use generated collision spheres

now it’s me who don’t get it - if you read closely the foremetioned sample you’ll find two kind of generated spheres that should cover all you doubts, as is:

collision sphere gathered from the egg model heart.egg

heartTrigger = loader.loadModel('heart')
heartTrigger.reparentTo(render)
heartTrigger.setPos(0, 25,0)
### >>>> here where the collision sphere is snatched off the egg
c = heartTrigger.find("**/collider")
c.node().setFromCollideMask(BitMask32.bit(LOVE_MASK))
###>>>> we set this object as a collision source
base.cTrav.addCollider(c, collisionQueue)

collsion sphere explicitly created inside the script

smileCollider = loader.loadModel('smiley')
smileCollider.reparentTo(render)
smileCollider.setPos(5, 25,0)
###>>>> the two following lines generate the collision sphere
cnodePath = smileCollider.attachNewNode(CollisionNode('cnode'))
cnodePath.node().addSolid(CollisionSphere(0, 0, 0, 1))
cnodePath.node().setIntoCollideMask(BitMask32.bit(LOVE_MASK))

is now clear enough?
anyhow if you got more doubts please add more details for what is not clear to you so I’ll be more to the point.

I ment your sample uses 1 egg file for both geometry and collision geometry.
In my example i try to use a separate file.
My example is just a small edit of the Pusher.py example from manual, which uses collision spheres generated by code. So I just added code to load a collision sphere from an egg file, and I removed the code which generates a col. sphere and the code which creates a CollisionNode (i read i dont need it when i load it from a file).
Thats about all i did.
You certainly are helpful but im just too stupid to understand BitMask32, entry, and stuff like that, which are in your tuts.

don’t say that - collisions aren’t a piece of cake so if you got some Q just ask and I guess somebody will try to explain you, don’t worry about - actually it’s holiday time for me so I try to help you out. By the way I recon the sample I did was not so obvious cos it take for granted maybe too much therefore I reedited in a different shape splitting it in 2 pieces: 1 reduced to the bone with just two objects in the scene and the second with masked applied so that one will learn gradually and should be more clear, at least this is what I hope. Just go there and download it again and lemme know if is clear enough now or what need more in case is not.

Hi, I have a question about collisions to. I made this code, but it isn’t working. Can sombady explain?

import direct.directbase.DirectStart 
from pandac.PandaModules import * 
from direct.showbase import DirectObject 
from direct.task import Task 
from direct.actor import Actor 
from direct.interval.IntervalGlobal import * 
from direct.gui.OnscreenText import OnscreenText 
from direct.task.Task import Task 
import math 

#Load the first environment model 
m = loader.loadModel("models/teapot") 
m.reparentTo(render) 
m.setScale(0.25,0.25,0.25) 
m.setPos(-17,0,8)  

#Load the first environment model 
s = loader.loadModel("models/levelmap") 
s.reparentTo(render) 
s.setScale(0.1,0.1,0.1) 
s.setPos(0,0,0)

#-------------------------------------------------------------------------
cnodePath1 = s.attachNewNode(CollisionNode('cnode1'))

quad1 = CollisionPolygon(Point3(-200, -35, -2), Point3(-200, -35, 65),
  Point3(-200, 35, 65), Point3(-200, 35, -2))


cnodePath1.node().addSolid(quad1)

quad2 = CollisionPolygon(Point3(-200, -35, 65), Point3(-80, -35, 65),
  Point3(-80, 35, 65), Point3(-200, 35, 65))


cnodePath1.node().addSolid(quad2)

quad3 = CollisionPolygon(Point3(-80, -35, 65), Point3(-80, -35, 47),
  Point3(-80, 35, 47), Point3(-80, 35, 65))


cnodePath1.node().addSolid(quad3)

quad4 = CollisionPolygon(Point3(-80, -35, 47), Point3(0, -35, 47),
  Point3(0, 35, 47), Point3(-80, 35, 47))


cnodePath1.node().addSolid(quad4)

quad5 = CollisionPolygon(Point3(0, -35, 47), Point3(0, -35, 30),
  Point3(0, 35, 30), Point3(0, 35, 47))


cnodePath1.node().addSolid(quad5)

quad6 = CollisionPolygon(Point3(0, -35, 30), Point3(65, -35, 30),
  Point3(65, 35, 30), Point3(0, 35, 30))


cnodePath1.node().addSolid(quad6)

quad7 = CollisionPolygon(Point3(65, -35, 30), Point3(115, -35, 15),
  Point3(115, 35, 15), Point3(65, 35, 30))


cnodePath1.node().addSolid(quad7)

quad8 = CollisionPolygon(Point3(115, -35, 15), Point3(115, -35, -2),
  Point3(115, 35, -2), Point3(115, 35, 15))


cnodePath1.node().addSolid(quad8)

quad9 = CollisionPolygon(Point3(115, -35, -2), Point3(-200, -35, -2),
  Point3(-200, 35, -2), Point3(115, 35, -2))


cnodePath1.node().addSolid(quad9)

quad10 = CollisionPolygon(Point3(-200, 35, -2), Point3(-200, 35, 65),
  Point3(-80, 35, 65), Point3(-80, 35, -2))


cnodePath1.node().addSolid(quad10)

quad11 = CollisionPolygon(Point3(-80, -35, -2), Point3(-80, -35, 65),
  Point3(-200, -35, 65), Point3(-200, -35, -2))


cnodePath1.node().addSolid(quad11)

quad12 = CollisionPolygon(Point3(-80, 35, -2), Point3(-80, 35, 47),
  Point3(0, 35, 47), Point3(0, 35, -2))


cnodePath1.node().addSolid(quad12)

quad13 = CollisionPolygon(Point3(0, -35, -2), Point3(0, -35, 47),
  Point3(-80, -35, 47), Point3(-80, -35, -2))


cnodePath1.node().addSolid(quad13)

quad14 = CollisionPolygon(Point3(0, 35, -2), Point3(0, 35, 30),
  Point3(65, 35, 30), Point3(65, 35, -2))


cnodePath1.node().addSolid(quad14)

quad15 = CollisionPolygon(Point3(65, -35, -2), Point3(65, -35, 30),
  Point3(0, -35, 30), Point3(0, -35, -2))


cnodePath1.node().addSolid(quad15)

quad16 = CollisionPolygon(Point3(65, 35, -2), Point3(65, 35, 30),
  Point3(115, 35, 15), Point3(115, 35, -2))


cnodePath1.node().addSolid(quad16)

quad17 = CollisionPolygon(Point3(115, -35, -2), Point3(115, -35, 15),
  Point3(65, -35, 30), Point3(65, -35, -2))


cnodePath1.node().addSolid(quad17)

cnodePath1.show()

#--------------------------------------------------------------------
segment = CollisionSegment(0, 0, 0, -5, 0, -10)

cnodePath2 = m.attachNewNode(CollisionNode('cnode2'))
cnodePath2.node().addSolid(segment)

cnodePath2.show()

segment2 = CollisionSegment(0, 0, 0, -5, 0, -10)

cnodePath3 = m.attachNewNode(CollisionNode('cnode3'))
cnodePath3.node().addSolid(segment2)

cnodePath3.show()

#--------------------------------------------------------------------
traverser = CollisionTraverser('traverser name') 
base.cTrav = traverser

#--------------------------------------------------------------------
handler = CollisionHandlerEvent()
handler.addOutPattern('cnode2-out-cnode1')

handler2 = CollisionHandlerEvent()
handler2.addInPattern('cnode3-into-cnode1')

#--------------------------------------------------------------------
class MyObject(DirectObject.DirectObject):
    def __init__(self): 
        self.accept('cnode2-out-cnode1', self.handler)
        self.accept('cnode3-into-cnode1', self.handler2)
    def handler(self, entry): 
        print 'entry'
        taskMgr.add(onderen, "potjemeet2")
        taskMgr.remove("potjemeet1")
    def handler2(self, entry):
        taskMgr.add(vooruit, "potjemeet1")
        taskMgr.remove("potjemeet2")

def onderen(task):
    m.setPos(m,0,0,-0.1)

def vooruit(task):
    m.setPos(m,0.1,0,0)
    return Task.cont

#
base.cTrav .addCollider(cnodePath2, handler) 
base.cTrav .addCollider(cnodePath3, handler2) 
# 
h = MyObject() 

run()

Like… make your own thread.

Well, that’s a rather rude way to point out that newbieeee should have created his own thread, isn’t it?

It IS rude ! :laughing:

handler.*Pattern("%fn-out-%in")

It is?
:frowning:
Sorry…
Now make your own topic :smiley: