Shooting

Hi Guys
when i try to shoot, the bullet just falls to the ground

var BulletPrefab:Transform;
var force : float = 999;

function Update()
{
if(Input.GetButtonDown("Fire1"))
{
var bullet = Instantiate(BulletPrefab, 

GameObject.Find("spawnpoint").transform.position, 

GameObject.Find("Mball").transform.rotation);

bullet.Rigidbody.AddForce(bullet.transform.forward * force);

}
}

any ideas on how to fix this?
thanks for your help

Well it could be that MBall is facing down, causing the bullet to shoot straight down

no that didnt seem to fix it, thanks anyway though.

Wait, its not that it shoots down, it just doesnt fire them at all, it just makes them appear.
it also displays the error : Null reference exception: object reference not set to an instance of object

Does your BulletPrefab have a rigidbody component?

Yeah it does have a the rigidbody component, is there anything special I had to set?
@runner that didnt work :frowning:

Going off of your error, one of these needs to be fixed.

  1. You don’t have a BulletPrefab attached via the inspector.
  2. There is no spawnpoint GameObject in the scene.
  3. There is no Mball GameObject in the scene.
  4. There is no rigidbody attached to the BulletPrefab.

You say it spawned, that knocks out option 1.
It has a rigidbody. That knocks out option 4.

You appear to be missing a GameObject or have it incorrectly named.

Make sure your bullet doesn’t spawn touching or inside another collider, it can make it do funny things. Also, what actually pops the null reference… what does it say is missing / null.

Thanks, I accidentlt had called Mball mball :slight_smile: