Skip to content

Commit 8f191f9

Browse files
authored
Normalize the direction vector in always_shift() (#839)
1 parent 247cdee commit 8f191f9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

manim/mobject/mobject_update_utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@ def always_redraw(func):
5959

6060

6161
def always_shift(mobject, direction=RIGHT, rate=0.1):
62-
mobject.add_updater(lambda m, dt: m.shift(dt * rate * direction))
62+
def normalize(v):
63+
norm = np.linalg.norm(v)
64+
if norm == 0:
65+
return v
66+
return v / norm
67+
68+
mobject.add_updater(lambda m, dt: m.shift(dt * rate * normalize(direction)))
6369
return mobject
6470

6571

0 commit comments

Comments
 (0)