Wednesday, September 7, 2022
HomeGame Developmentbox2d - Perpendicular inelastic joint of two our bodies in PyBox2d

box2d – Perpendicular inelastic joint of two our bodies in PyBox2d


I want to create two objects of various density and (inelastically) weld them perpendicular collectively, in order that the ultimate object varieties an L. Afterwards, I need to have the ability to assign a place and velocity to the newly welded object.

I attempted to make use of CreateWeldJoint within the instance beneath. Nonetheless, I’m not certain find out how to use it accurately and up to now I did not discover any helpful info. What I’ve up to now appears as follows:

enter image description here

The picture exhibits, that the joint of each our bodies is just not utterly inelastic.

How can I take advantage of CreateWeldJoint or another methodology, to weld two objects collectively at a 90 angle? How can I make the weld / joint utterly inelastic?

from Box2D.examples.framework import Framework, predominant
from Box2D import b2EdgeShape, b2FixtureDef, b2PolygonShape


class TestObject(Framework):

    def __init__(self):
        tremendous(TestObject, self).__init__()

        # World
        self.world.gravity = (0.0, 0.0)

        self.world.CreateStaticBody(
            shapes=[
                    b2EdgeShape(vertices=[(-10, 0), (10, 0)]),
                    b2EdgeShape(vertices=[(-10, 0), (-20, 20)]),
                    b2EdgeShape(vertices=[(10, 0), (20, 20)]),
                ]
        )

        obj_vertices = [(1.0, 1.0), (-1.0, 1.0), (-1.0, -1.0), (1.0, -1.0)]
        velocity = (0.0, -10.0)

        # First object
        top = 4
        width = 1

        obj1 = self.world.CreateDynamicBody(place=(15, 20), linearVelocity=velocity)
        obj1_vertices = [(width * item[0], top * merchandise[1]) for merchandise in obj_vertices]
        obj1_shape = b2PolygonShape(vertices=obj1_vertices)
        obj1_fixture_def = b2FixtureDef(form=obj1_shape, density=1)
        _ = obj1.CreateFixture(obj1_fixture_def)

        # Second object
        top = 2
        width = 1

        obj2 = self.world.CreateDynamicBody(place=(15, 16), linearVelocity=velocity)
        obj2_vertices = [(width * item[0], top * merchandise[1]) for merchandise in obj_vertices]
        obj2_shape = b2PolygonShape(vertices=obj2_vertices)
        obj2_fixture_def = b2FixtureDef(form=obj2_shape, density=10000)
        _ = obj2.CreateFixture(obj2_fixture_def)

        # Weld each objects
        obj_welded = self.world.CreateWeldJoint(
            bodyA=obj1,
            bodyB=obj2,
            localAnchorA=(0, -7),
            # localAnchorB=(0, -4),
            # referenceAngle=90,   # doesn't work
            # frequencyHz=0.0,
            # dampingRatio=0.0,
        )
        # obj_welded.CreateFixture(b2FixtureDef(place=(0, 40), linearVelocity=(0, 0)))   # doesn't work


    def Step(self, settings):
        tremendous(TestObject, self).Step(settings)


if __name__ == "__main__":
    predominant(TestObject)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments