Matheart / manim-physics

Physics simulation plugin of Manim that can generate scenes in various branches of Physics.
317 stars 28 forks source link

Turn off gravity for rigid body #25

Open freQuensy23-coder opened 1 year ago

freQuensy23-coder commented 1 year ago

I want to turn off gravity for one scene, but methods from pymunk docs does not works. Firstly I tryied to change scene space gravity paramether in construct method:

def construct(self):
        self.space.gravity = 0, 0```

But it doesn't help Then i tried to override init method for Space scene class, but it did not bring any result

    def __init__(self, renderer=None, **kwargs):
        self.space = Space(gravity=(0, 0))
        super().__init__(renderer=renderer, **kwargs)

Full code:

from manim import *
from manim_physics import *

class FirstScene(SpaceScene):   
    def __init__(self, renderer=None, **kwargs):
        self.space = Space(gravity=(0, 0))
        super().__init__(renderer=renderer, **kwargs)

    def construct(self):
        self.space.gravity = 0, 0
        c1 = Circle(color="red").shift(2* LEFT)
        c2 = Circle(color="blue").shift(RIGHT)
        self.make_rigid_body(c1, c2)
        c1.body.velocity = (1, 0)
        self.wait(10)
icedcoffeeee commented 1 year ago

The GRAVITY attribute can be set like so:

class FirstScene(SpaceScene):
    GRAVITY = (0, 0)

    def construct(self):
        c1 = Circle(color="red").shift(2 * LEFT)
        c2 = Circle(color="blue").shift(RIGHT)
        self.make_rigid_body(c1, c2)
        c1.body.velocity = (1, 0)
        self.wait(10)
freQuensy23-coder commented 1 year ago

It does not help. When you run your code, you get this result video

icedcoffeeee commented 1 year ago

Interesting, I can't reproduce this. Can you provide your manim version and OS information? Just for clarity: can you confirm you've done the following steps:

  1. The python file only contains:
    
    from manim import *
    from manim_physics import *

class FirstScene(SpaceScene): GRAVITY = (0, 0)

def construct(self):
    c1 = Circle(color="red").shift(2 * LEFT)
    c2 = Circle(color="blue").shift(RIGHT)
    self.make_rigid_body(c1, c2)
    c1.body.velocity = (1, 0)
    self.wait(10)
2. Save the file.
3. In the terminal, run:
```terminal
manim file_name.py -pql