Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chaining Hinges behaviour #162

Open
fjavierv opened this issue Oct 4, 2022 · 0 comments
Open

Chaining Hinges behaviour #162

fjavierv opened this issue Oct 4, 2022 · 0 comments

Comments

@fjavierv
Copy link

fjavierv commented Oct 4, 2022

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)

      })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant