Making camera follow panda actor

I’m trying to make the camera follow the panda actor in 3rd person mode. This is the link to my code ->
For some reason, it keeps giving me this error

Known pipe types:
(all display modules loaded.)
2019-11-25 19:58:13.620 Python[10532:359092] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Traceback (most recent call last):
  File "/Users/38167/PycharmProjects/viren/", line 39, in <module>
    app = MyApp()
  File "/Users/38167/PycharmProjects/viren/", line 28, in __init__
    self.taskMgr.add(, "camera")
  File "/Users/38167/PycharmProjects/viren/venv/lib/python3.7/site-packages/direct/task/", line 384, in add
    task = self.__setupTask(funcOrTask, name, priority, sort, extraArgs, taskChain, appendTask, owner, uponDeath)
  File "/Users/38167/PycharmProjects/viren/venv/lib/python3.7/site-packages/direct/task/", line 404, in __setupTask
    'add: Tried to add a task that was not a Task or a func')
  File "/Users/38167/PycharmProjects/viren/venv/lib/python3.7/site-packages/direct/directnotify/", line 130, in error
    raise exception(errorString)
Exception: add: Tried to add a task that was not a Task or a func

it would be a great help if anyone could figure out why this is happening, thanks!

Hi, welcome to the forums!

You have a name conflict: you named a variable, but you also created a method def camera, which is also stored by Python in Therefore, the error says that you are trying to pass your camera object into taskMgr.add instead of the method.

You should simply rename one or the other. For example, you could rename your method to def camera_task().

Since the primary class in the program inherits from “ShowBase”, “” is presumably the default system camera (i.e. what might otherwise be accessed as “”). Thus it’s probably better to rename the method than the camera!

Just tried your solution and it works! Thanks for the help and happy coding!!! I still have one question though, when I did it my mouse no longer could look around, is there a way of preventing this?

The default mouse look is really only meant for basic debugging and it’s typical that users will call self.disableMouse() and instead implement their own mouse navigation.

That said, if you wish to control the camera in a way compatible with the built-in mouse navigation, then you can instead use self.trackball.node().setPos() instead. (Note that the coordinates are not quite the same way as they are when manipulating

Ok so I tried following your instructions as best as possible and ended up with this:

   def camera_task(self, task):
        self.trackball.node().setPos(self.pandaActor.getX(), self.pandaActor.getY() + 15, -4)
        return Task.cont

and yes I did have to manipulate the coordinates a bit.

So I guess what I’m asking is what did that do to the camera? When I ran the script it just kinda looked towards the panda’s direction but did not follow it which made seeing the panda actor hard.