Force - 2D Physics in PlayBasic

## Force

Acceleration doesn't happen by itself, even though I presented it that way in the last chapter to keep things simple. Objects do not simply start accelerating for no reason. Instead :

• Acceleration is the result of the application of force.

For example, a car will accelerate because the motor is pushing it. A can of beans thrown out of the window of an airplane will accelerate downwards because gravity is pulling it. Because force comes in many varieties, some of which we know little about, force is defined this way :

• Force is anything capable of changing an object's acceleration.

The force of thrusters on a spaceship will accelerate it. The force of a bullet will shatter a vase in a million pieces, causing the pieces to quickly accelerate (even if they fly in different directions).

In the last code example from the last chapter you were actually applying a force to the dot by pressing the left and right keys. This can be made clear by modifying the code a bit to show the "acceleration" as thrust. The code below works exactly like the code from the last chapter except I have included red dots to show where the thrust is coming from as well as splitting the xAcceleration# variable into two - leftThrust# and rightThrust#. Lastly, the force is "pushing" rather than "pulling".

``````x# = 400
y# = 300
leftThrust# = 0.01 ; 1 cppl
rightThrust# = -0.01
xSpeed# = 0

SetFPS 60
Do

x# = x# + xSpeed#
Cls 0
If RightKey()
xSpeed# = xSpeed# + rightThrust#
DotC x#+3,y#, rgb(255,0,0)
EndIf
If LeftKey()
xSpeed# = xSpeed# + leftThrust#
DotC x#-3,y#, rgb(255,0,0)
EndIf
Print "xSpeed : " + str\$(xSpeed#)
Circle x#, y#, 2, 1
Dot x#, y#
Sync
Loop```
```

## Net Force

Net force is the total sum of all forces affecting an object.

#### Balanced Force

If two forces are acting on an object in opposite directions they will cancel out. Therefore, run the code above again, but this time press both the LEFT and RIGHT arrow keys at the same time. You will see that the dot will go absolutely nowhere. If it does move slightly, it is because you failed to hit the keys at exactly the same moment (which is easy to do, running at 60 FPS).

Now, get the dot moving and then press both left and right at the same time. The dot's speed will not change. This is known as balanced force.

#### Unbalanced Force

To get an object moving when two forces are applied, there must be unbalanced force. Unbalanced force is when the two (or more) forces do not equal out. The equation for unbalanced force (and indeed balanced force) is this :

````net force = force 1 + force 2`
```

So if several forces are acting on an object these can be summed to one single net force which is used to calculate the acceleration for the object for that perticular loopin.

#### Net Force — Again

Forces are not always opposed. Much of the time the forces acting on an object come from two different directions. When this happens, the resulting effect is a combination of the forces. For example, if we were to push the dot from the left side and from the bottom the combined force results in movement at an angle. The following code example allows you to fire thrusters on all four sides of the dot to illustrate this concept :

``````x# = 400
y# = 300

VertThrust# = 0.01 ; 1 cppl
HortThrust# = 0.01

xSpeed# = 0
ySpeed# = 0

SetFPS 60

Do

x# = x# + xSpeed#
y# = y# + ySpeed#

Cls 0
Print "xSpeed : " + str\$(xSpeed#)
Print "ySpeed : " + str\$(ySpeed#)

Circle x#, y#, 2, 1

If RightKey()
xSpeed# = xSpeed# + -HortThrust#
DotC x#+3,y#, rgb(255,0,0)
EndIf
If LeftKey()
xSpeed# = xSpeed# + HortThrust#
DotC x#-3,y#, rgb(255,0,0)
EndIf
If UpKey()
ySpeed# = ySpeed# + VertThrust#
DotC x#, y# - 3, rgb(255,0,0)
EndIf
If DownKey()
ySpeed# = ySpeed# + -VertThrust#
DotC x#, y# + 3, rgb(255,0,0)
EndIf

Sync
Loop```
```
page revision: 15, last edited: 15 Jul 2012 02:14