C# Basic Shooting Script

Im making a 2d platformer with basic object throwing but when the object is shot it just falls to the ground like the AddForce isn’t working on it. Plz help

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(CharacterController))]

public class Movement : MonoBehaviour
{
    public float speed = 6.0f;
	public float bulletSpeed = 1000.0f;
    public float jumpSpeed = 8.0f;
    public float gravity = 20.0f;
	public float shotInterval = 0.5f;
	public Rigidbody bulletPrefab;
	
	private float shootTime = 0.0f;
    private Vector3 moveDirection = Vector3.zero;
    private bool grounded = false;
	private Transform bulletSpawn;
	
	void Start(){
		bulletSpawn = transform.Find ("bulletSpawn");	
	}
    void FixedUpdate() 
    {
        if (grounded) 

        {
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, 0);
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= speed;

            if (Input.GetButton ("Jump"))
				moveDirection.y = jumpSpeed;
        }
		
        moveDirection.y -= gravity * Time.deltaTime;
		
        CharacterController controller = (CharacterController)GetComponent(typeof(CharacterController));
        CollisionFlags flags = controller.Move(moveDirection * Time.deltaTime);
        grounded = (flags & CollisionFlags.CollidedBelow) != 0;
		
		if (Input.GetButton ("Fire1"))
		{
			if (Time.time >= shootTime)
			{ 
				Rigidbody bullet = Instantiate(bulletPrefab, bulletSpawn.position, bulletSpawn.rotation) as Rigidbody;
				bullet.rigidbody.AddForce(transform.forward * bulletSpeed);
				shootTime = Time.time + shotInterval;
	    	}
		}
	}
}

Remove gravity from rigidbody, also if the bullet Spawn prefab has Vector3.forward as its y axis. Quaternion.identity should fix that, but if it doesn’t manually create vector3 to change the euler angles(in instantiation). also since you instintiate as a prefab gravity is auto on. call buletspawn.gravity.enabled = false imediatley after instantiation. hope that helps

I found that it was shooting into the map and therefore appearing to just fall when it was shooting straight sorry to waste your time :frowning: