## Basics of Motion Physics

Before we get into working with moving objects in Unity, I would like to take some time to talk about some basic motion physics. This tutorial will build a baseline of concepts that we can use when moving objects in Unity. This tutorial will cover Newton's Three Laws of Motion, Speed, Velocity, Acceleration, Mass, and Forces.

## Newton's Three Laws of Motion

Newton's three laws of motion give us a basis for all of concepts of physics that we are going to learn about. They aren't super exciting. The main thing to take away here is that they form the basis of all motion physics.

1. Objects at rest stay at rest and objects in motion stay in motion unless acted on by an external force.

2. Describes how the velocity of an objects changes when subject to an external force.

F = m * a

3. Every action has an equal and opposite reaction.

2. Describes how the velocity of an objects changes when subject to an external force.

F = m * a

3. Every action has an equal and opposite reaction.

## Speed

Speed is scalar quantity that refers to how fast an object is moving. It is the rate at which an object is covering a distance. A fast moving object covers a large distance and a slow moving object covers a shorter distance. An object that is not moving has zero speed. Some examples of the units that speed can have are Miles Per Hour (MPH), Meters per Second (m/s), and Feet per Second (ft/s).

## Velocity

Velocity is a vector quantity that describes the rate that an object is changing its position. This differs in speed in that the direction and displacement of the object matters. For example, an object that moves away from a point in space 2 units in 1 second in the x direction and then moves back towards that point 2 units in 1 second would have a velocity of zero because it did not displace its position at all. The object would have a speed of 2units/second however, because it took 2 seconds to move 4 units. Another important aspect to consider with velocity is that there is a direction involved. For example, an object which moves 4 units to the right in 1 second in the x direction could be said to have a velocity of [4,0,0] units/second.

v = df - di / t

The notation that I just showed you shows both the direction and the magnitude of the velocity. v is the velocity, df is the final distance, di is the initial distance, and t is the amount of time it takes to travel that distance. This will be very useful when we are programming movement in Unity. Unity objects move in 2d or 3d space using x,y,z coordinates. Time is constantly running in Unity therefore the first topic we talked about with moving forward and backward for zero velocity is a lot less useful than the second one.

In Unity, we can directly change the velocity of an object using the Rigidbody.velocity or Regidbody2d.velocity property. Doing so may not result in realistic physics, but may be useful if you want instantaneous bursts of velocity. A couple of examples would be a player jumping or a projectile shooting.

v = df - di / t

The notation that I just showed you shows both the direction and the magnitude of the velocity. v is the velocity, df is the final distance, di is the initial distance, and t is the amount of time it takes to travel that distance. This will be very useful when we are programming movement in Unity. Unity objects move in 2d or 3d space using x,y,z coordinates. Time is constantly running in Unity therefore the first topic we talked about with moving forward and backward for zero velocity is a lot less useful than the second one.

In Unity, we can directly change the velocity of an object using the Rigidbody.velocity or Regidbody2d.velocity property. Doing so may not result in realistic physics, but may be useful if you want instantaneous bursts of velocity. A couple of examples would be a player jumping or a projectile shooting.

## Acceleration

Acceleration has to do with the change in velocity that an object undergoes. It is a vector value therefore it has both a magnitude and a direction. A common misconception with acceleration is that objects that are moving very fast or very slow have great or little acceleration. This is a false however. An object that is moving very fast, but is not changing its velocity actually has a 0 acceleration. One measurement of acceleration is m/s^2 notice that we add an additional 1/s to the velocity. This is because we are showing a change in velocity over some time period.

a = vf-vi / t

Acceleration that is negative, also called deceleration, is acceleration that is moving in the opposite direction of a moving object. The negative portion of deceleration does not come from the magnitude of the acceleration, it comes from the direction. Deceleration has a positive magnitude with a negative direction.

In Unity, you cannot directly edit the acceleration of an object. Most of the time, you will probably use trial and error for the look and feel of the acceleration you are trying to achieve. If you want an exact value, you can calculate acceleration of objects using the math that we have learned so far.

a = vf-vi / t

Acceleration that is negative, also called deceleration, is acceleration that is moving in the opposite direction of a moving object. The negative portion of deceleration does not come from the magnitude of the acceleration, it comes from the direction. Deceleration has a positive magnitude with a negative direction.

In Unity, you cannot directly edit the acceleration of an object. Most of the time, you will probably use trial and error for the look and feel of the acceleration you are trying to achieve. If you want an exact value, you can calculate acceleration of objects using the math that we have learned so far.

## Mass

Mass is a fundamental property of objects which is a numerical measurement of the amount of matter in an object. It is directly related to the concept of Inertia which is an object's ability to resist changes in motion. Different materials have different amount of mass. For example, a 1m^3 block of iron is less likely to move than a 1m^3 block of cotton. Do not confuse the concept of mass with weight. Weight is a vector quantity that is dependent on the mass of an object and gravity. Gravity may change, and in Unity you can change gravity so that it does not have to be down towards the ground.

In Unity, you are able to change the mass of an object in the editor. Making an object have more mass will make it harder to move with physics, while making an object have less mass will make it easier to move. When you are editing mass in Unity, think of objects in proportions and not as values. An object with a mass of 5 is 5x heavier than an object with a mass of 1 regardless of what the units are.

In Unity, you are able to change the mass of an object in the editor. Making an object have more mass will make it harder to move with physics, while making an object have less mass will make it easier to move. When you are editing mass in Unity, think of objects in proportions and not as values. An object with a mass of 5 is 5x heavier than an object with a mass of 1 regardless of what the units are.

## Force

Force is the last concept that we will talk about in this tutorial. In Newton's second law of motion we saw that Force = mass x acceleration. Force is another vector value and usually has unit of measurement; Newtons. The composition of a Newton is 1kg * m/s^2. A newton is the amount of force necessary to accelerate a kilogram of mass at a rate of 1 meter per second squared. Therefore, higher amounts of force will move objects faster.

In Unity, you are able to add forces to objects using some methods in the Rigidbody and Rigidbody2d Classes. Again, like mass, think of force like an arbitrary number. A force of 1 will be able to move an object with a mass of 1 at an acceleration of 1m/s^2.

In Unity, you are able to add forces to objects using some methods in the Rigidbody and Rigidbody2d Classes. Again, like mass, think of force like an arbitrary number. A force of 1 will be able to move an object with a mass of 1 at an acceleration of 1m/s^2.

For more tutorials, follow us on Twitter and Youtube!