Categories
Uncategorised

Experimenting with Matter Physics

This week, I looked into the Matter physics engine that is present in Phaser. Once I had a basic project in place, I looked around at some Phaser examples I thought about implementing into the project to see how Matter works and what it can do.

The first thing I tried was to spawn a bunch of small particle objects that would move and bounce around. I made a simple image that I could use to be the particle and then worked on implementing them to the game. The actual particle itself worked similar to implementing a sprite, with specifying a loctaion and texture, the Matter stuff came in after than where an object was needed to assign a hitbox shape and size and various other properties.

One particle coming up!

Once I had a particle stored in a variable, I could change various properties about the particle like its mass and friction, luckily a lot of this is in the documentation so I can find what I need pretty quick

The properties I added to my particle

Now I just needed to make a lot of them, nothing that a simple for loop can’t do! With that in place I loaded up my level and bam, a bunch of particles falling from the sky!

Interesting weather today, isn’t it?

Some of them like to go through the floor, I can only presume that it’s perfectly landed in between the gap for 2 tiles so i’m not too sure how to solve that just yet, but hopefully soon I can find the culprit.

Another thing that caught my eye on the examples page was some cloth physics that looked interesting, they used a soft body to create it so I suppose I should follow suit if I want to make my own.

Huh, seems simple enough

Put the cloth into the scene and bam…?

That’s not a cloth!
Oh dear, what have I created…

Surprisingly if you don’t make any points static, it will just drop and make a mess, so yes thats a cloth, just not the one I envisioned. So I had to make the top points static so it would hang like a flag, luckily the example had me covered, as it stored the points row by row so a for loop checking the first row of items and making them static should work, but it seems like I needed to assign each point to a constant before I could.

Right that should stop that from happening again!

With that in place, all that was left was to test it. Fingers crossed!

That’s more like it!

Matter certainly seems like a very fun physics engine to play around it and would like to do more work around it, especially with things like stopping particles going through the ground and giving soft bodies a texture, but overall I had a lot of fun playing around with this and would like to make a game using Matter.