Firing projectiles in the direction of movement
Another common use of force is to apply a force to a newly instantiated object, making it a projectile travelling in the direction the Player's GameObject is facing. That's what we'll create in this recipe. The result of following this recipe should look as follows:

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 this 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
). Set its size as (0.5, 0.5, 0.5
). - Add a
RigidBody
component to the Sphere (go toPhysics | RigidBody
). - In the
Project
panel, create a new blue Material namedm_blue
(go toCreate | Material
). - Apply the
m_blue
Material to your sphere. - In the
Project
panel, create a new Prefab namedprefab_projectile
. - Drag the sphere...