Firing projectiles in the direction of movement
Another common use of force is to apply it to a newly instantiated object, making it a projectile traveling in the direction that the player’s GameObject faces. That’s what we’ll create in this recipe. The result of this recipe should look as follows:
Figure 11.13: Projectiles being fired by the player’s object
In the preceding screenshot, on the left, we can see a player-controlled tank, while on the right, we can see three sphere projectiles that have been fired from the player’s character.
Getting ready
This recipe builds upon the player-controlled 3D cube Unity project that you created at the beginning of this chapter. So make a copy of that project, open it, and then follow the steps for this recipe.
How to do it...
To fire projectiles in the direction of movement, follow these steps:
- Create a new
Sphere
GameObject (by navigating to Create | 3D Object | Sphere...