Question: > 
> ` public class Shoot : MonoBehaviour {
> 
> 
> 

```
 public GameObject shell;
 public Transform barrelEnd;
 public float launchForce = 200;

 void Update () {

     if (Input.GetButtonDown("Fire1"))
     {
         Fire();
     }
 }
 void Fire()
 {
     Rigidbody projectile;
     projectile = Instantiate(shell, barrelEnd.position, barrelEnd.rotation) as Rigidbody;
     projectile.AddForce(0, 0, launchForce);

 }
}

```

In Unity3d, all I want to do is instantiate a shell and launch it. When I play, it will instantiate the shell but it does not launch it, it just drops. I don't understand why I keep getting this error. Clearly i've already created an instance of an object correct? Any help is much appreciated!

Answer: 
Your problem is you are not instantiating a `Rigidbody`, you are instantiating a `GameObject` which contains a `Rigidbody` as a component.

When you use `as` and you try to cast it to something that the object is not it sets the cast `null`. Change the cast to a `GameObject`, then use [`GetComponent`](https://docs.unity3d.com/ScriptReference/GameObject.GetComponent.html) to get the `Rigidbody` and it should work.

```
projectile = Instantiate(shell, barrelEnd.position, barrelEnd.rotation) as GameObject;
Rigidbody rb = projectile.GetComponent<Rigidbody>();
rb.AddForce(0, 0, launchForce);

```
This error can appear for many reasons.

Make sure that `shell` and `barrelEnd` are assigned in the Editor. If that is done then you need to getComponent from the Object you just instantiated.

Unless you camera is **always** facing the Z axis, there would be a problem in this line of code `projectile.AddForce(0, 0, launchForce);`.

If this is an FPS game with camera that moves around, use `cameraTransform.forward` to make the bullet always shoot forward/away from the camera.

```
public GameObject shell;
public Transform barrelEnd;
public float launchForce = 200;

Transform cameraTransform;

void Start()
{
    cameraTransform = Camera.main.transform;
}

void Update()
{

    if (Input.GetButtonDown("Fire1"))
    {
        Fire();
    }
}
void Fire()
{
    GameObject tempObj;
    tempObj = Instantiate(shell, barrelEnd.position, barrelEnd.rotation) as GameObject;
    Rigidbody projectile = tempObj.GetComponent<Rigidbody>();

    projectile.velocity = cameraTransform.forward * launchForce;
}

```