Game Development Reference
In-Depth Information
As you would expect, we are going to handle mouse left-click as fire command. When the
player fires the weapon, he casts a ray towards the aim position of the crosshair. This ray is
the bullet fired from the weapon, and we are going to be able to check if it hit something
and handle the hit. The main script in shooting mechanism is RaycastShooter , shown in
Listing 49. Before discussing the details of the script, we need to know a number of basic
properties of the ray cast shooter, which are listed below:
1. The shooter casts one ray at a time.
2. The ray has a maximum range that can be set from the inspector.
3. There is a time gap between two consecutive ray casts (fire rate).
4. Ray shooter has vertical and horizontal thresholds of inaccuracy, which are ex-
pressed in terms of maximum angle between the ray that passes through the center
of the crosshair and the actual ray cast by the shooter. Each time a ray is cast, it is
going to be rotated around x and y axes by a random value between positive and
negative values of the threshold.
5. The shooter has a configurable value for damage caused by its bullets. This
value represents the maximum damage when the target is at zero distance from the
shooter. The damage power decreases as the distance between the shooter and the
target increases, until it reaches zero at the maximum range of the shooter.
Search WWH ::




Custom Search