Bullet won't fly forward
Hello, i wrote this script to make my bullet fly:
using UnityEngine;
using System.Collections;
public class HealthShoot : MonoBehaviour {
public GameObject BulletPrefab;
public GameObject cameraobj;
void Start () {
BulletPrefab = Resources.Load("Bullet") as GameObject;
}
void Update () {
if (Input.GetKeyDown(KeyCode.Mouse0))
{
GameObject projectile = Instantiate(BulletPrefab) as GameObject;
projectile.transform.position = cameraobj.transform.position + cameraobj.transform.forward * 0.6f;
Rigidbody rb = projectile.GetComponent<Rigidbody>();
rb.velocity = cameraobj.transform.forward * 40;
}
}
}
And when i shoot my bullet (depending on what direction i'm turned), bullet fly a little bit to right or left, what's wrong?
Comment