How do i make the camera look at and object while its moving?

So, I have this code here and i wanted the camera to look at the panda while it’s moving.

    self.panda = loader.loadModel("models/panda-model")
    self.panda.reparentTo(render)
    self.panda.setScale(0.003)
    self.panda.setPosHpr(-20, 0, 0, 0, 0, 0)
    Sequence(self.panda.posInterval(3, Point3(20, 0, 0))).loop()

    self.cam.setPos(0, -20, 5)
    self.cam.lookAt(self.panda)

Have you disabled the default camera controller yet? If not, add base.disableMouse() somewhere (or self.disableMouse() in your ShowBase subclass).

Yes, I have but what I’m trying to do is make the camera point at the panda while it is moving without actually reparenting it onto the panda. The panda is moving using posIntervals so I can just use hprIntervals for the camera but it won’t be as efficient. I tried doing

self.cam.lookAt(self.panda)

but the hpr doesn’t change when the panda moves

You need to keep calling self.cam.lookAt() to keep repositioning the camera as the panda moves. You can use a task to do this:

def cam_control(task):
  self.cam.lookAt(self.panda)
  return task.cont

self.taskMgr.add(cam_control, "Camera Controller")

Yeah, that works. I just need to play around with it some more to get it perfect but thanks for the help.