Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

140
Visualizações
¿Cómo hago que el objeto caiga al impactar en Matter.js?

Estoy usando Matter.js para algunos gráficos y quiero este rectángulo.

 let title = Bodies.rectangle(w / 2.4, height / 1.8, 300, 100, { isStatic: true, })

para obtener isStatic: false y caer cuando es golpeado por algunos círculos que llueven sobre él. He buscado mucho en Google, pero realmente no he encontrado nada más que esto:

 Events.on(engine, 'collisionStart', function (event) { event.pairs.forEach(function (obj) { console.log( 'BodyA is static: ' + obj.bodyA.isStatic + '. BodyB is static: ' + obj.bodyB.isStatic ) }) })

Esto me da todas las colisiones que ocurren, pero no he descubierto cómo configurar isStatic: false cuando algo golpea. ¡Aprecio tu ayuda!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Puede llamar a Matter.Body.setStatic(body, false) en el cuerpo en cuestión para activarlo.

Aquí hay un ejemplo:

 const engine = Matter.Engine.create(); const render = Matter.Render.create({ element: document.body, engine, options: {width: 400, height: 400, wireframes: false}, }); const fallingBody = Matter.Bodies.rectangle( 200, 0, 20, 20, { frictionAir: 0.1, density: 0.8, render: {fillStyle: "red"}, }, ); const wall = Matter.Bodies.rectangle( 200, 150, 400, 20, { frictionAir: 0.05, isStatic: true, render: {fillStyle: "green"} }, ); Matter.Composite.add(engine.world, [fallingBody, wall]); Matter.Events.on(engine, "collisionStart", event => { if (wall.isStatic && event.pairs.some(e => Object.values(e).includes(wall))) { Matter.Body.setStatic(wall, false); } }); Matter.Render.run(render); Matter.Runner.run(Matter.Runner.create(), engine);
 <script src="https://cdnjs.cloudflare.com/ajax/libs/matter-js/0.18.0/matter.min.js"></script>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda