cannon-es icon indicating copy to clipboard operation
cannon-es copied to clipboard

Chaining Hinges behaviour

Open fjavierv opened this issue 3 years ago • 0 comments

Hi, I do not know if the following behaviour is expected when I am chaining hinges:

Screenshot from 2022-10-04 15-32-50

You can see how the shaft are bent, It do not happend with only one constraint. The following code is created from Hige example:

      demo.addScene('Hinge', () => {
        const world = demo.getWorld()
        world.gravity.set(0, -20, 5)

        const mass = 1
        const size = 5
        const distance = size * 0.1

        const shape = new CANNON.Box(new CANNON.Vec3(size * 0.5, size * 0.5, size * 0.1))
        
        const hingedBody = new CANNON.Body({ mass })
        hingedBody.addShape(shape)
        world.addBody(hingedBody)
        demo.addVisual(hingedBody)

        const hingedBody2 = new CANNON.Body({ mass })
        hingedBody2.addShape(shape)
        world.addBody(hingedBody2)
        demo.addVisual(hingedBody2)

        const hingedBody3 = new CANNON.Body({ mass })
        hingedBody3.addShape(shape)
        world.addBody(hingedBody3)
        demo.addVisual(hingedBody3)

        const staticBody = new CANNON.Body({ mass: 0 })
        staticBody.addShape(shape)
        staticBody.position.y = size + distance * 2
        world.addBody(staticBody)
        demo.addVisual(staticBody)

        // Hinge it
        const constraint = new CANNON.HingeConstraint(staticBody, hingedBody, {
          pivotA: new CANNON.Vec3(0, -size * 0.5 - distance, 0),
          axisA: new CANNON.Vec3(-1, 0, 0),
          pivotB: new CANNON.Vec3(10, size * 0.5 + distance, 0),
          axisB: new CANNON.Vec3(-1, 0, 0),
        })
        world.addConstraint(constraint)

        // Hinge it
        const constraint2 = new CANNON.HingeConstraint(hingedBody, hingedBody2, {
          pivotA: new CANNON.Vec3(0, -size * 0.5 - distance, 0),
          axisA: new CANNON.Vec3(-1, 0, 0),
          pivotB: new CANNON.Vec3(10, size * 0.5 + distance, 0),
          axisB: new CANNON.Vec3(-1, 0, 0),
        })
        world.addConstraint(constraint2)

        // Hinge it
        const constraint3 = new CANNON.HingeConstraint(hingedBody2, hingedBody3, {
          pivotA: new CANNON.Vec3(0, -size * 0.5 - distance, 0),
          axisA: new CANNON.Vec3(-1, 0, 0),
          pivotB: new CANNON.Vec3(10, size * 0.5 + distance, 0),
          axisB: new CANNON.Vec3(-1, 0, 0),
        })
        world.addConstraint(constraint3)

      })

fjavierv avatar Oct 04 '22 13:10 fjavierv