bullet always go to the right side

hello everybody i have a simple problem but i can’t fix it

here is my script
`#pragma strict

var SpeedBullet : float = 500;

function Start ()
{
rigidbody.AddForce(transform.forward * SpeedBullet);
}`

i also have a script to shoot

`#pragma strict

var Bullet : GameObject;
var FirePoint : GameObject;
var Ammo : int = 30;

var FireMode : String = “Semi”;

function Start ()
{

}

function Update ()
{
if(FireMode == “Semi”)
{
if(Input.GetMouseButtonDown(0))
{
FireOneBullet();
}
}
}

function FireOneBullet()
{
Instantiate(Bullet, FirePoint.transform.position, transform.rotation);
Ammo–;
}`
so when i click the left mouse button the bullet should go forward but he going right and when i walk 90 degrees i alse go right there must be somthing but i can’t see it

thanks for the help

If you have the script that instantiates the bullet attached to eg an empty GameObject that is at the ending of your guns barrel then you can just rotate the empty GameObject. If you have it attached to your gun then you should change it in the way I said.

I am not an expert at JS but one problem that I had when I was making a bullet script was where I put the script. Make sure to put the script on the camera, not the gameobject that is shooting, so that the bullet will go straight out from the camera not the gameobject. Of course this is if your making a FPS which I’m guessing you are. So here is an example script that I put onto the main camera that is following my gameobject:

#pragma strict
var arrow:Transform;
var shootforce:float;
 
function Update () {
 
    if(Input.GetMouseButtonUp(0))
    {
        var instanceArrow = Instantiate(arrow, transform.position, transform.rotation);
        instanceArrow.rigidbody.AddForce(transform.forward * shootforce);
    }
 
}

The above code is written in JS.

Like HexadimensionalerAlp said, you should instanciate your Bullet on a gameobject position & rotation.
Right now you instantciate on FirePoint position but your rotations are the same of the object who contain your script. If this object is not on the good orientation your bullet neither.

Try with something like this :

private Quaternion rotInit;
private Vector3 FirePoint;


function Update()
{
 rotInit = gun.transform.rotation;
 FirePoint = gun.transform.position;
}

function FireOneBullet() { 
    Instantiate(Bullet, FirePoint, rotInit); 
    Ammo--; }

Gun should be your gun :slight_smile:
His blue Axis must be in front of him because you are using transform.forward

Here you got a good way to create a projectile.

thnx al of u have fix my problem