I am fairly new to Unity, I have a question regarding shooting bullets in the direction that the sprite is moving. I have looked at the following 2 tutorials:
while both come close to a solution, I can’t seem to figure out the best way to achieve the desired effect. Both of the tutorial above use either a cursor to aim and shoot or directional keys to rotate the sprite.
I need the sprite to be able to move in 8 directions with animations using the arrows keys and using the Fire1 button to shoot a bullet. I do not know how to get the bullet to travel in the direction the sprite is moving at the time it is fired.
It depends on how you are moving the bullets. Using Translate() or AddForce(transform.up) the bullet can be instantiated to the same rotation as the player. Using AddForce(Vector2) the bullet needs the global values depending on which way the player is facing. e.g.
Based on your feedback, I used the animator to get the direction of the character. using that direction I was able to apply the correct rotation and offset to the bullet object to get the desired effect. Below is the code that I am using to do this.
I am not sure if this is the best way to go about this, but for now it is working and I can start looking in to other parts of the game. Thank you so much for your help and guidance, it really helped me out.