• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Physics Engine Pixels to Meters

R

Robzoid

Guest
I'm working on a 2D billiards/pool game and figured this would be a good place to use the GameMaker physics engine. This is my first time using it. I'm concerned I'm not understanding the "Pixels to Meters" field in the Room Editor. By default, it has a value of 0.1.

upload_2019-9-7_19-56-5.png

I figure a "Pixels to Meters" value of 0.1 means 1 pixel is 0.1 meters - so 0.1 is the meters per pixel value ( 1 meter / 10 pixels = 0.1). The pool table I am modeling is 8 feet long, which is 2.4384 meters. My pool table sprite is 1050 pixels wide. 2.4384 m / 1050 px is 0.00232.

upload_2019-9-7_20-1-18.png

upload_2019-9-7_20-20-45.png

The problem is that a value of 0.00232 makes the balls travel way too fast. Things worked relatively smoothly at 0.1. Am I doing something wrong here? I couldn't find much documentation on the physics engine. I've also heard some bad things about the Gamemaker physics engine. So, feel free to let me know if you think hard coding the physics without using the physics engine is the best way to go.
 

FrostyCat

Redemption Seeker
Your balls would not have moved too fast if you scaled down the impulses and forces to match. The figures you used to make things work at 0.1 would have to be 50 times smaller to look the same at 0.002.

I'm not sure where you got news about "bad things about the physics engine", but most of it comes from people who learned defective technique from HeartBeast and turned it on for projects that should have it off. Pool is a perfectly fine use case for the physics engine, in fact there's an older tutorial for it.
 
According to my tests,

phy_mass = pixels_per_meter^2 * area_in_pixels * density

In order to have the same mass, you'd need to set the denisty to 1857.907 times whatever it was before. Or the forces used would need to be reduced by the same factor.

But do you even need to change pixels_per_meter to begin with? If you were having good results with the old value, why not keep using it?
 

Bart

WiseBart
I couldn't find much documentation on the physics engine.
The manual is actually pretty clear already on the definition of the pixel to meter scale (under physics_world_create).

It is indeed rather limited when it's about actually using the physics engine. These recent tech blog articles may be of use: https://www.yoyogames.com/blog/69/physics-in-gamemaker-studio-2-part-1

Also, an interesting thing to be aware of is that GameMaker uses Box2D as a physics engine.
If there's something that's not in the manual, you can likely find an answer online.
For the pixel to meter scale, for example, there's an FAQ on the project wiki.

Many of the answers are already out there :)
 

SCR

Member
I have always thought that calling it "pixels to meters" is a bit confusing. What they are really asking for is a conversion factor (in units of "meters per pixel") that will be used to convert pixels to meters:

pixels * conversion_factor = meters

Using the example in the GMS manual, for a system where 32 pixels represents 1 meter, they suggest the following code:

physics_world_create(1/32); //notice that they are using the reciprocal of pixels-per-meter, which is a little easier to grasp: 1 / (32 pixels per meter)
 
Top