gun problems (shooting)

when i create my own guns using blender and import them into unity a problem occurs when i add a script which makes my gun fire. what happens is when i shoot the bullet dosent come out the end of my gun instead it fires to the right of my gun which makes it look stupid. this only happens with guns that i have made unlike the 2 guns that you get when you download the fps tutorial from the unity website they work fine.

can anyone help me?

Look in your gun script, and somewhere you will see something that looks like this:

Vector(??,??,??);

You will have some zeros in there, most likely two. Like so:

Vector(0, 0, ??);

What you might need to do is change the numbers around until it fires in the right direction, like so:

Vector(??, 0, 0);

or

Vector(0, ??, 0);

Some of your code looks like this:

if(Input.GetButtonDown("Fire1"))
{
var clone : Rigidbody; clone = Instantiate(projectile, transform.position,transform.rotation)
}

When you use "transform.position" as of where you want the "bullet" to be spawned form, then the engine will automaticly fire from the objects "pivot point" if i do remember correctly that is in the center of the object(it might differ, but whatever)

If you use:

gameObject.Find("Type the objects name you want the bullet to be spawned form").transform.position;

What you should do is make a object(a cube for example) then name the cube "BulletSpawnPoint"

an instead of typing:

`transform.position` type

gameObject.Find("BulletSpawnPoint").transform.position;

This should solve your problem, if you undestand it ;P please tell if you dont.

Does your bullet start at the right place ? Freeze motion of the bullet and fire and see if its spawned in the correct position...

I suspect you have the wrong direction for the motion, as in your gun isn't facing its forward vector. There are a lot of ways to deal with this, but I recommend moving the bullet into world space directions, Position is world position if your bullet point ( should be a scene node ) and you can either set velocity or do .addForce in a camera.forward vector. This will get you a step closer but bullets will still go sideways in travel from your gun.

In my games I have always created a vector from the gun tip to the projected screen center from the camera. I dont recommend using your gun's forward vector though, as bullets will go flying in random directions based on your animations. If a player shoots while running and the gun swings back and forth, your bullet will fly everywhere...

In general though I would offer this advice and for testing problems like this you will want to use the OnDrawGizmos function. Render out your vectors so you can see where your coordinate spaces are going wrong...

private Vector3 BulletVelocity;
    private Transform Bullet;
    //Somewhere in your script:  BulletVelocity = ..... 

public void OnDrawGizmos() 
{
    Vector3 ourPosition = Bullet.position;
    Gizmos.color = new Color (1, 0, 0, 1);
    Gizmos.DrawLine(ourPosition, ourPosition+BulletVelocity);
    }