My bullets are fired at different angles in different directions

Hello.
I’m making a shooter/platform game on Unity, but I have a problem with my bullet directions.
When I fire my gun depending on my default camera angle, my bullets move in a straight line without any problems, but when I turn my player left/right, my bullets go to very different places.

When I turn 180 degrees from my character’s camera angle, the bullets come out from the back of the gun, not from the tip. When I turn left, the weapon shoots from the left side, and when I turn right, the gun shoots from the right side.

Here’s my code block, I can only add one example picture below because I’m newbie here, but I will add a sample picture below showing the direction the bullets go when I fire the gun.

  1. My weapon code:
public class WeaponControl : MonoBehaviour
{
    public LayerMask obstacleLayer;
    public Vector3 offset;

    RaycastHit hit;

    public GameObject bullet;
    public Transform firePoint;

    private void Update()
    {
        //Look

       if(Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, Mathf.Infinity, obstacleLayer))
        {
            transform.LookAt(hit.point);
            transform.rotation *= Quaternion.Euler(offset);
        }


        //Fire
        if (Input.GetMouseButtonDown(0))
        {
            GameObject instantiatedBullet = Instantiate(bullet, firePoint.position, firePoint.rotation);

            Rigidbody bulletRb = instantiatedBullet.GetComponent<Rigidbody>();
            if (bulletRb != null)
            {
                bulletRb.linearVelocity = firePoint.forward * 30f;
            }


        }

    }
}
  1. My bullet code:
public class Bullet : MonoBehaviour
{
    public float speed = 100f;

    

    private void Update()
    {
        transform.Translate(transform.forward * Time.deltaTime * speed);
    }
}

Bullet directions example;

I started coding one month ago. I wrote these lines of code by researching here and there on the internet, so I may have basic errors :> Can you please explain by simplifying and explaining?

My guess is that firePoint is not a child of the gun?

Also side note I’m not sure why you’re using that raycast.

I put the firePoint into the weapon in the hierarchy menu and it sits right on the tip.
I also added firepoint in the script component I added to the weapon. I think there is something wrong with my codes but I’m not exactly sure what it is.

The firing and bullet code look ok unless I’m missing something. Not sure what the looking code is, I’m guessing some kind of auto aim? Can you maybe show a screenshot of your hierarchy and inspector?

Of course,

Of course but for some reason, Unity’s spam bot hiding my post. I think it’s because I’m trying to upload images even though it’s my first post. Sorry for the inconvenience but I’ll write it down manually :frowning:

► Directional Light
► Floor
► Bullet
► Player
CheckGround (inside the player)
▼ Main Camera
▼ Gun
firePoint (inside the gun)

I assume the WeaponControl script is in the Gun game object? Not sure what could be wrong if so.