CollisionSegment Example with Moving Target

Can someone give me an example of using a CollisionSegment between a camera and a moving target(3d person camera view). I’m using this to detect objects that get in the way of the camera and I couldn’t find a good example of CollisionSegment being used.

Thanks :slight_smile: .

So you guys can tell me where I’m going wrong in my camera manager when I initialize it I am doing.

 
raygeometry =  CollisionSegment(self.camera.getPos(), self.target.dogModel.getPos())
     
        
      
        self.cameraCollider = self.camera.attachNewNode(CollisionNode('CameraNode'))
        self.cameraCollider.node().addSolid(raygeometry)
        self.cameraCollider.node().setFromCollideMask(BitMask32.bit(2))
        self.cameraCollider.node().setIntoCollideMask(BitMask32.allOff())

and then in my cameras update loop I’m doing this.

 self.cameraCollider.node().modifySolid(0).setPointA(self.camera.getPos())
        self.cameraCollider.node().modifySolid(0).setPointB(self.target.dogModel.getPos())

which I want it to produce results like this:

but instead produces results like this:

I feel like my ray is wrong or I’m not setting ti right. I’m grateful for an help on what I might be doing wrong here. Thanks!

I note that your ray is a child of the camera, therefore it automatically inherits the camera’s position. So setting point A to camera.getPos() is adding the camera’s position to itself, and setting point B to dog.getPos() is just the wrong thing altogether.

Probably you intended your ray to be a child of render instead of the camera. Then you can use camera.getPos() and dog.getPos() in the way you are using them.

David