How do I keep the angle of a body in pybox2d betwe

2019-07-31 09:24发布

问题:

In the pybox2d manual it states the following:

pybox2d uses radians for angles. The body rotation is stored in radians and may grow unbounded. Consider normalizing the angle of your bodies if the magnitude of the angle becomes too large (use b2Body.SetAngle).

However, when I try to implement something to 'normalize' the angle I get the following error:

AttributeError: 'b2Body' object has no attribute 'SetAngle'

Code snippet:

def update_outputs(self):

    # This is necessary to prevent the angle
    # from getting too large or small
    self.body.SetAngle(self.body.angle % 2*pi)

回答1:

Looks like the library has been pythonized since those docs were written. angle is a property of Body:

@angle.setter
def angle(self, angle):
    self._xf.angle=angle
    self._transform_updated()

You should be able to simply set it with something like:

def update_outputs(self):

    # This is necessary to prevent the angle
    # from getting too large or small
    self.body.angle %= 2*pi