3rd person following camera

Hi, I have a task here that makes the camera “follow” an actor. But when I execute a pos seqence for that actor, the camera does not follow it very smoothly. It seems to be sort of jumpy:

        def _follow_player(task):
            base.camera.setPos(player.getX()-4, self.getY()-4, 5)
            return Task.cont

        taskMgr.add(_follow_player, "camera_follow")

is this the right approach doing this kind of thing? Thanks for any comments.


That’s the right approach. The thing you have to keep in mind when you have a task that moves the camera relative to some other node, is that you should be sure that the other node gets its position updated before the camera task runs. Otherwise, the camera will be updating itself to the node’s position in the previous frame, which can look jumpy.

So the right solution depends on how player is being updated. If it is being updated with another task, or by an interval, then you just need to specify that your camera_follow task runs later:

taskMgr.add(_follow_player, "camera_follow", priority = 35)

If, on the other hand, it is updated by the animation code itself, as the exposed joint of an actor Actor object, then call actor.update() as the first operation within your task.


Score! Thanks.