Game Development Reference
In-Depth Information
If you have played a significant number of Pong games, you may have noticed
that the ball sometimes gets stuck horizontally; this is very boring. In order to
avoid this, let's introduce a disturbance. You will monitor the ball, and as soon
as it is stuck horizontally or vertically, you will add a random effect to change the
next bounce. To achieve this objective, you must monitor the linear velocity of
the ball. The linear velocity is the motion among the axis of the 2-D plan. If the
linear velocity of the Y is 0, this means that the ball keeps a constant Y position.
In other words, your ball is moving at a perfect horizontal movement (the ball is
stuck between the left and right wall). If the linear velocity of the X is 0, this
means that the ball keeps a constant X position. In other words, your ball is
moving at a perfect vertical movement.
Click Create Rule and add the condition ''Attribute''''ball.Motion.Linear
Velocity.Y''''=''''0''. Drag and drop a Rule behavior and add the condition ''Actor
receives event''''overlaps or collides'' with ''actor with tag''''collidable.'' Then
drag and drop a Change Attribute behavior and change ball.Motion.Linear
Velocity.Y to random (70,120). Your rule should be similar to Figure 4-7.
Figure 4-7. Preventing horizontal jam
Click Create Rule and add the condition ''Attribute''''ball.Motion.Linear
Velocity.X''''=''''0''. Drag and drop a Rule behavior and add the condition ''Actor
receives event''''overlaps or collides'' with ''actor with tag''''collidable.'' Then
 
Search WWH ::




Custom Search