Camera rotation issue

I’m using this code to rotate camera with right mouse button drag:

def mouse_task(self, task):
        is_down = self.mouseWatcherNode.is_button_down
        left_mouse =
        right_mouse = MouseButton.three()
        dt = globalClock.get_dt()

        pointer =
        x = pointer.get_x()
        y = pointer.get_y()

        if self.mouseWatcherNode.has_mouse():
            if is_down(left_mouse):
                print("mouse left is down:", self.mouseWatcherNode.get_mouse())

            if is_down(right_mouse):
                if not self.is_mouse_down:
                    # Remember mouse position
                    self.mouse_start_x = x
                    self.mouse_start_y = y
                    self.is_mouse_down = True
                    yaw = + (self.mouse_start_x - x) * dt * 10
                    pitch = + (self.mouse_start_y - y) * dt * 10
                    pitch = max(-1 * self.max_pitch, min(self.max_pitch, pitch))
                    # print("mouse: %s, %s" % (x, y))
          , pitch, 0)

                    # Remember mouse position
                    self.mouse_start_x = x
                    self.mouse_start_y = y
                self.is_mouse_down = False
                self.mouse_start_x = None
                self.mouse_start_y = None

        return Task.cont

It works but at some point camera heading(yaw) gets jumpy! specially when i drag mouse from the left edge of the window to right it jumps at ~-40 into ~-52.7 even though i tried to drag slowly.
This is all package: (2.96 MB)
Forgive my stupid model :smiley:

I’ve found out this jumpiness in camera rotation happen when camera is about to show new objects that was not in camera view before.
For example if there is a cube out of the camera view and then i started to rotate camera towards that cube, at some point a sudden jump in rotation happens. this happen only once for that cube. once it renders the camera rotation will act as expected.
I’ve tested this on more complex scene(from blender) with about two hundreds objects and the camera rotation get weird jumps until all objects get their first render in camera view.
So is there any solution or workaround for this?

I found a workaround. first i put camera far away of my model while camera look at it, then in a task i set camera position into desired one:

def render_task(self, task):
    if task.time < 1.0:
        return task.cont, 0, 35)
    return task.done