bullets with wrong angle

when i shoot the bullets go in the right direction but at the wrong angle
heres my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gun : MonoBehaviour
{

public Transform bulletSpawnPoint;
public GameObject bulletPrefab;
public float bulletSpeed = 10;

public Vector2 turn;

private void Update()
{
    turn.x += Input.GetAxis("Mouse X");
    turn.y += Input.GetAxis("Mouse Y");

    if(Input.GetMouseButtonDown(0))
    {
        var bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
        bullet.GetComponent<Rigidbody>().velocity = bulletSpawnPoint.forward * bulletSpeed;
    }
}

}

2 Answers

2

Bullet.transform.rotation = Quaternion.lookRotation(rigidbody.velocity)

You use the bulletSpawnPoint direction to instantiate your bullet. Is the bulletSpawnPoint align in the direction (rotation wise) of where you want the bullet to go ?

yes that's right already, the bullets go where I want them to go but they are going facing down, I wanted to know if there was a way to rotate the prefab or something like that

The third parameter (bulletSpawnPoint.rotation) of the Instantiate function is the rotation of the bullet when it is instantiated.