見出し画像

Pixel Game Maker MV: Intro To Physics, Part 1

INTRO
Welcome to the beginner’s explanation of using physics in Pixel Game Maker MV!

In this part 1, we will cover the basics:

  • What is game physics?

  • What physics concepts does Pixel Game Maker MV implement from physics?

  • How is this reflected in the settings provided by Pixel Game Maker MV?

A part 2 will cover basic implementation of these objects.

The knowledge in this part 1 should be generic enough that with creative thinking it can be applied to any game engine that supports 2D physics.


WHAT IS GAME PHYSICS?

Real-life physics is the method, usually mathematical, of how we describe the interactions between different objects/types of matter. Thus, game physics is merely a simplified version of those rules. Pixel Game Maker MV (PGMMV), like most 2D game engines, is not attempting to be a true-to-life representation of physical properties. Instead, we focus on the basic concepts behind what is typically called Newtonian physics. This can be summed up most succinctly as “describing the motion of objects through some volume.”

Game physics is used to provide more of the randomization and organic feel to a game without the need for the developer to think of every possible situation. Sometimes this randomization/organic feel can lead to less-than-desirable results, but it is generally quicker to implement than bespoke custom solutions when you want something like a bouncing ball.


WHAT SETTINGS DOES PIXEL GAME MAKER MV PROVIDE?

There are 5 fundamental variables used by Pixel Game Maker MV in its physics Object calculations. 2 are regular Object variables and 3 are physics-only variables.

Physics Settings
  1. Object Weight (Physics Calculations Only)

    1. Object Weight is described by 2 variables, Mass and Density

      1. Mass is the total weight of that object. Kilograms are used as the unit.

      2. Density is the ratio of mass to volume. Big but light objects have a low density (a balloon), while small but very heavy objects have a high density (a lead weight).

    2. By default, all objects in PGMMV are assigned a Density of 1 and the mass is calculated automatically based on the X/Y size of the object.

    3. After the Object is created, you are free to change the values as you see fit. Adjusting the Density will automatically update the Mass value.

    4. Only Objects have these Weight settings.

  2. Friction (Physics Calculation Only)

    1. Friction is assigned via the Friction Factor slider. The default value is 0.50

    2. Friction is used to calculate how 2 Objects slow each other down when they are touching. This is the same principle used for most bicycle brakes!

    3. Objects and Tiles have a Friction Factor slider.

  3. Rebound Factor (Physics Calculation Only)

    1. Rebound is, essentially, how bouncy an Object is.

    2. The slider is set to 0.50 by default.

    3. This is a minor variable only used to modify the results of a physics collision.

Object Movement Settings
  1. Movement Speed (Object Variables)

    1. Movement speed is the representation of how fast the Object is moving.

    2. Object movement speed is normally calculated directly from the Normal Move and Accelerated Move Parameters, but the actual movement speed is also directly updated by the Physics system when physics is enabled for the Object.

    3. Only Objects have Movement Speed settings.

      1. Particle calculations are separate from the physics system in PGMMV.

  2. Gravity (Object Variable)

    1. Gravity determines how quickly Objects fall down when they are not on the ground.

    2. The default value for all Objects is 1.00. 

    3. Gravity can be changed on a per-Object basis, as needed, even if making a physics-based project.

    4. Only Objects have Gravity settings.

There are also a variety of prefab-ed Physics Widgets (called Parts in the PGMMV UI) that have additional physics parameters:

Rope Settings
  1.  Bonds

    1. Bonds tie a non-physics Object to either a Circle or a Square Physics Part

    2. Bonds have no special variables but are fundamental to implementing the physics system in PGMMV.

  2. Ropes

    1. Ropes connect 2 physics Objects together via a rope.

    2. The stiffness of the rope is controlled by the Partition Count variable.

      1. A low count rope is very stiff and doesn't bend well.

      2. A high count rope is very flexible and will have a lot of bounciness to it. But this increases processing load.

  3. Springs

    1. Acts as a spring, typically between 2 points.

    2. The strength of spring (how fast or slowly it contracts/expands) is controlled by the Spring Constant, Attenuation Factor, and Natural Length variables.

      1. The Spring Constant, also known as k in Hooke’s Law, determines how much the spring can stretch or compress when weight is applied.

      2. The Attenuation Factor controls the maximum amount of stretching or compression the spring will accept (springs cannot break in PGMMV) and how quickly it will return to normal when the load is removed.

      3. Natural Length is the initial length of the spring. By default it is set as the X/Y length of the spring when placed into the scene, but it can be changed to a value different from the visual representation.

  4. Axis

    1. Provides a motor-power axis capable of spinning a physics Object

    2. The direction of rotation can be configured.

    3. Braking force can be configured.

      1. Off by default.

      2. Brake strength is represented by the “Attenuation (During Brakes) variable.

    4. Target RPM is controlled by the Speed (RPM) variable

      1. This determines the maximum number of rotations per minute the axis will spin at when there is no weight on the axis.

    5. A Torque value is also provided.

      1. Torque determines how much weight the Axis is capable of spinning before it slows down or stops.

      2. Torque is a measure of force, not weight, and is configured using values of Newton-Meters.

  5. Explosions

    1. Provides an explosive force.

    2. Objects caught in the explosion will be their movement speed affected by the Strength, Speed (Time Until Max), Effective Distance, and Direction of the explosion.

      1. Effective distance does not fall off, as it is not a real explosion simulation. Only limiting factor is time spent within the explosion's area of effect.

  6. Gravity/Repulsion field

    1. This widget generates either an additional gravitational field effect, or a repulsive force.

    2. By default, it follows a falloff within the field, but the field can be configured to apply a constant force.

    3. Primary variables are Strength (of the Field), Effective Distance, and the Direction of the field.

Axis Settings

WHAT IS IT ALL USED FOR?

With these variables, a variety of properties can be easily (via mathematical formulae) derived. But it all comes down to Object movement! The gravity, friction, torque, and all these other variables are simply used to calculate how a Physics Object should now be moving!

On each physics calculation interval, each Physics Object and Widget provides useful information via all the variables described above. These variables are tallied and run through basic physics formulae to determine, at the end of the interval, the current movement speed & direction (that is properly called a vector) of each Physics Object.

As a developer, you don’t even need to fully understand the mathematics behind how each variable is applied. Just remember that each variable is just a representation of a movement parameter.

Next time I’ll go over how to create physics Objects in Pixel Game Maker MV and begin to cover how the different variables all interact! A lot of the general information has been provided here, which means some of you might be able to experiment and figure out the rest on your own. However, there’s a lot of finesse that goes into getting good results, which I will try to provide in part 2!


この記事が気に入ったらサポートをしてみませんか?