Home Game Development box2d – Perpendicular inelastic joint of two our bodies in PyBox2d

box2d – Perpendicular inelastic joint of two our bodies in PyBox2d

0
box2d – Perpendicular inelastic joint of two our bodies in PyBox2d

[ad_1]

I wish to create two objects of various density and (inelastically) weld them perpendicular collectively, in order that the ultimate object types an L. Afterwards, I would like 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. However, I’m not positive use it accurately and to date I did not discover any helpful data. What I’ve to date seems as follows:

enter image description here

The picture reveals, that the joint of each our bodies shouldn’t be fully inelastic.

How can I exploit CreateWeldJoint or another technique, to weld two objects collectively at a 90 angle? How can I make the weld / joint fully inelastic?

from Box2D.examples.framework import Framework, most important
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
        peak = 4
        width = 1

        obj1 = self.world.CreateDynamicBody(place=(15, 20), linearVelocity=velocity)
        obj1_vertices = [(width * item[0], peak * 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
        peak = 2
        width = 1

        obj2 = self.world.CreateDynamicBody(place=(15, 16), linearVelocity=velocity)
        obj2_vertices = [(width * item[0], peak * 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__":
    most important(TestObject)

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here