physics_mass_properties

With this you can apply specific mass properties to a fixture.

Syntax:

GML Code Example

physics_mass_properties(mass, local_center_x, local_center_y, inertia)


Argument Description
mass The new mass that you want the fixture to have.
local_center_x The local x coordinate of the new center of mass.
local_center_y The local y coordinate of the new center of mass.
inertia Set the inertia for the fixture.


Returns: N/A


Description

This function can be used to set custom mass and inertia values for a physics enabled instance. Normally the mass, center of mass, and inertia for an instance is calculated using a combination the surface area of the bound fixtures and their density. However in very special occasions you may need to offset the center of mass or change the inertia and that is when you would use this function. Bear in mind that the mass is calculated in real world weight (ie:kilograms) and you should always try and keep values realistic for what you are modelling. So if your physics object is meant to represent a person, their mass would be approximately 70 kilos.

The center of mass is calculated automatically for you based on the shape of the fixture (or fixtures) you have defined. To get a general idea of where this could be, if you have a sprite that is the same shape as the fixtures you wish to create, then select the "center origin" option you will see approximately where the center of mass will be too. However, this may not be correct or you may be looking for a specific effect from your physics object, in which case this function can also be used to change the x and y coordinates for the center of mass. These are local values, so 0,0 is the point at which the fixtures are bound to the instance (the origin of the instance). So a center of mass of -4,0 would shift the center of mass to the left of the origin.

As for the inertia, this basically defines how resistant the instance is to changes in its direction and velocity, so a higher inertia makes it more resistant and a low inertia makes it less resistant (inertia and mass cannot be negative values!).

NOTE: This function does not set mass and inertia for individual fixtures, but rather for the whole physics enabled instance, no matter how many fixtures are bound to it.

NOTE: This function should only be used when necessary as the physics simulation is designed for the mass and inertia to be optimal based on the density and size of the fixture. Changing these values can have unforeseen effects.


Example:

GML Code Example

physics_mass_properties(phy_mass, -10, -10, phy_inertia);

The above code will shift the center of mass of the physical body to the left.





No Examples Submitted

Does this page need better examples? Be the first to Submit

No Edits Suggested

Is this page unclear or not descriptive enough? Suggest an edit to the page and with enough upvotes your changes will be made.

No Questions Have Been Ask

Do you have a question about this page? Ask it Here