Home > Software engineering >  manim camera.move_to and camera.scale at the same time don't work
manim camera.move_to and camera.scale at the same time don't work

Time:02-27

Here is a sample code:

from manim import *
import numpy as np


class Problem(MovingCameraScene):
    def construct(self):
        circle_left = Circle(radius=2).move_to(np.array([-3, 0, 0]))
        circle_right = Circle(radius=2).move_to(np.array([3, 0, 0]))
        self.add(circle_left, circle_right)
        self.wait()
        self.play(self.camera.frame.animate.move_to(circle_left.get_center()), self.camera.frame.animate.scale(2))
        self.wait()

What I don't understand is why it just zooms out and doesn't moves to the left and zooms out at the same time, only to end up centered around circle_left AND zoomed out. It looks like self.camera.frame.animate.move_to(circle_left.get_center()) was ignored.

I know that separating them in two self.play works but I would like both the zooming out and the moving to the left circle happening at the same time :/

Thanks for the help!

CodePudding user response:

Manim doesn't handle simultaneous animations called on the same mobject in that manner. Instead, you can actually chain animations with the .animate syntax to get the effect you want. So:

self.camera.frame.animate.move_to(<code>).scale(<code>)

Refer to the tutorial in the docs for more context:

https://docs.manim.community/en/stable/tutorials/building_blocks.html#animating-methods

  • Related