Chapter     14

Firing Weapons

Many games require the player to fire or throw weapons at obstacles or enemies. If you have ever tried to fire weapons, you have likely encountered problems in getting your projectiles to leave your character in a predictable manner, and travel along a set path to a target.

Weapons can come in many shapes, sizes, and functions. Bullets, in many gaming situations, travel in straight lines, as do missiles, lasers, and most other propelled weapons. Thrown weapons, such as rocks, grenades, and even arrows to an extent, follow trajectories that are more parabolic. Regardless of the image or animation that you choose to use for the weapon, the math for getting it from point A to point B will be mostly the same.

This chapter ...

Get Android Game Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.