Questions tagged [matter.js]

Matter.js is a 2D physics engine for the web

About

Matter.js is a JavaScript 2D rigid body physics engine for the web

Links

295 questions
29
votes
3 answers

Disabling gravity in Matter.js

Is there any way to disable gravity in Matter.js? I want my objects (bodies) to keep their physical abilities (like reaction to collision, restitution, friction etc), but I'd like to prevent the reaction to device's gyro and orientation change.
Igal
  • 5,833
  • 20
  • 74
  • 132
22
votes
4 answers

Prevent force-dragging bodies through other bodies with MatterJS

I'm using MatterJs for a physics based game and have not found a solution for the problem of preventing bodies being force-dragged by the mouse through other bodies. If you drag a body into another body, the body being dragged can force itself into…
d13
  • 9,817
  • 12
  • 36
  • 44
20
votes
4 answers

Matter.js change colors

I'm working with matter.js on a small project. I'm tryin to change the background color of the canvas and add custom colors to objects. Does anyone know a tutorial or something for styling matter.js Matter.js
user1399844
18
votes
1 answer

2D soft bodies: Gelly and moldable?

I am using Matter.js physics in an attempt to create soft bodies. I was able to create a body like this: However I am not sure if this is the "soft body" I want. It is true that this body is not entirely rigid and has that bouncy feel when it…
Kunis
  • 576
  • 7
  • 24
13
votes
3 answers

Matter.js calculating force needed

Im trying to apply a force to an object. To get it to move in the angle that my mouseposition is generating relative to the object. I have the angle targetAngle = Matter.Vector.angle(myBody.pos, mouse.position); Now I need to apply a force, to…
Kylie
  • 11,421
  • 11
  • 47
  • 78
13
votes
1 answer

Change default canvas size in matterjs

I'm trying to override the default canvas size that is set to: 800x600 After some digging in the documentation I found: Matter.Render.create([options]) And the options that seem interesting are: render.options.height and render.options.width. How…
kemicofa ghost
  • 16,349
  • 8
  • 82
  • 131
12
votes
2 answers

JavaScript, Matter.js: Disable collision for one body

As already mentioned in the title, I am looking for a way, to disable every collision of a body in Matter.js. It should still be linkable with Constraints, and there should be the possibility of enabling the collision again after some time. Is there…
d0n.key
  • 1,318
  • 2
  • 18
  • 39
10
votes
2 answers

matter.js mouse click on body

I have some code like the following for the matter.js library: // create two boxes and a ground var boxA = Bodies.rectangle(400, 200, 80, 80); var boxB = Bodies.rectangle(450, 50, 80, 80); var ground = Bodies.rectangle(400, 610, 810, 60, { isStatic:…
Ian
  • 900
  • 2
  • 9
  • 19
8
votes
2 answers

Phaser 3: Matter physics detect collision

I am trying to detect when two object collide with each other, but I am not sure how to do it. I have the following scene, which adds two physics images to the scene. I just need a way to detect when the two collide. export class MainGame extends…
Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338
8
votes
5 answers

Import matter-js in typescript project

I found this file : https://www.npmjs.com/package/@types/matter-js i execute this line : npm install --save @types/matter-js In root ts file i got error message : 'Matter' refers to a UMD global, but the current file is a module. Consider…
Nikola Lukic
  • 4,001
  • 6
  • 44
  • 75
8
votes
4 answers

How to make minimal example of matter.js work?

I'm trying to use the matter.js physics library. I'm using their "getting started" tutorial, but it can't find the canvas. Here is my html: Physics test