In the previous video, I have configured the player to be rotated towards mouse position. I have also realized that the image of the player object is rotated 90 degrees, so I have put Z-rotation to 90 degrees.
A cool feature that I want to add is the ability to shoot objects at different directions. In order to do that, you have to add a new C# script, that will contain some parts of an already existing script, but will be used specifically for the object that rotates towards mouse position.
Script explanation
The introduction of New Input System is very important. This script will have the same parts like in one of the previous tutorials, but unlike the previous script for shooting, it won’t have the transform rotate because the object will be rotated according to mouse position. So, let’s move on to the next part: You need to add these three components: a spawn position, prefab and shooting speed. These three are very important, because you need to spawn an object at a specific position and at a specific speed. The part of the script that is located in void OnShoot() will be identical to the previous script.
This script uses the same code from one of the previous videos. The top down space shooter requires the use of bullet spawning, but does not require gravity.
Extra tip
Although it is not mentioned in the video, you should put the line rb2d.gravityScale = 0; before the line that says rb2d.AddForce() and that will disable the gravity of the spawned objects. This tip can be explained in a short video that can also become part of the tutorial series.
No responses yet