0
\$\begingroup\$

This is not covered anywhere in the documentation that I can find.

I am using the physics engine, and the reported phy_position_x and x values are different, such that (phy_position_x, phy_position_y) is (0, 0) and (x, y) is (origin x, origin y).

Why are they different and is one preferred over the other in code?

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

You can see the documentation for all three:

x

Returns: Real

Description: The x value of an instance is the horizontal position in the current room, measured in pixels. This value can be either 0, positive or minus, where 0 is the left hand side of the room and moving right increases x, moving left decreases x (a negative value for x means that the instance has gone outside the left side of the room). You can even give x a real value like 12.345, but as you cannot get .345 of a pixel, the instance may not appear to have moved, although these values will be maintained and used internally by GameMaker: Studio and are perfectly valid.

By setting the x (and y) values you can make the object jump around the room to the position of your choice, or you can add and subtract to them by smaller amounts to give the illusion of movement without actually using the built in speed and direction functions. This should be taken into account when making your games as often one type of movement lends itself to a particular style of game-play more than another.

phy_position_x

Returns: Real

Description: This variable can be used to get (or to set) the x position of the instance within the game room physics world. Please note that the physics world may present errors when instances are moved by directly setting this variable as it will interrupt the continuous simulation.

phy_com_x

Returns: Real

Description: This read-only variable will return the x position of the instances center of mass. This is calculated automatically based on the density, inertia and mass of the instance as defined by the appropriate functions.

As the name implies, the phy_position_x is the position of the physics object that's representing the object. It's different from the phy_com_x because the phy_com_x is at the center of the mass of the physics object, most likely at the center of the object.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for this; I am familiar with those definitions. I'm looking for the practical difference between x and phy_position_x on a physics-enabled object. Can you improve upon or make a clearer explanation than the answer I made on this question? That would drive at the heart of my confusion. \$\endgroup\$ Commented Feb 16, 2015 at 16:26
  • \$\begingroup\$ The practical difference is they're used for different things. Most things will be defined by their center or top left. You'll find both varieties here. \$\endgroup\$
    – House
    Commented Feb 16, 2015 at 17:16
0
\$\begingroup\$

phy_position_x and phy_position_y are the position variables for use on a physics enabled world. x and y variables are the position of an object in a world (room) without physics.

That's the diference of them.

\$\endgroup\$
0
\$\begingroup\$

It appears that phy_position_x and phy_position_y are in the top-left of the object fixture.

x and y are at the sprite origin.

The phy_com_x and phy_com_y are at the center point of the fixture. These are usually the same as the sprite origin. In the documentation, linked here, there is a way to modify this, but initially it is the center of the collision shape from the Physics panel.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .