I was about halfway through the course when I discovered this and i’m not sure if this is covered later in the course but if you’re holding the mouse button down to fire the gun and you bring the mouse pointer to the barrel of the gun between the guns position and the bullet spawn points position the player and gun face the correct direction but your bullets shoot from the back of the gun and travel the opposite direction than you’re gun is aiming. Just thought I would bring this up as I cant quite figure out how to fix it.
Hi Metzitron,
I’ve had a look at my project and found the same issue!
The easiest solution that i have found is to move the bullet spawn point back into the gun towards the handle as cosmetically it very hard to see any issue with the bullet being inside the gun rather than at the muzzle location.
The issue occurs to the difference in position of where we flip the character sprite and the bullet spawn point.
Hope this helps tweak it a little
Your solution did work…sort of… I had an issue where while aiming at a steep angle the bullet would appear to fire from out of the top or bottom of the barrel slightly but i did find a pretty simple solution.
I figured since we already had the gun rotating towards the mousePos that I could just fire the bullet based on the direction the gun was aiming
All I had to do was change the Init() Method in the Bullet class. Instead of setting the bullets position to the bulletSpawnPos i set the bullets transform.position = gun.transform.position and change the _fireDirection to = (bulletSpawnPos - (Vector2)transform.position).normalized;
after a bit of lining up the positions of the bullet spawn position, gun, and gun sprite gameobjects it shoots as expected and removes the mouse position out of the bullet direction entirely
now I just hope I don’t regret the change in an upcoming lecture
public void Init(Gun gun, Vector2 bulletSpawnPos)
{
isReleased = false;
_gun = gun;
transform.position = gun.transform.position;
_fireDirection = (bulletSpawnPos - (Vector2)transform.position).normalized; //(mousePos - bulletSpawnPos).normalized;
}
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.