using UnityEngine;
using System.Collections;
public class PlayerGunController : MonoBehaviour
{
public GameObject bullet;
public int speed;
public Transform shotSpawn;
public float fireRate;
private float nextFire;
void Update ()
{
if(Input.GetMouseButtonDown(0) && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
Instantiate(bullet, shotSpawn.position, shotSpawn.rotation);
bullet.rigidbody.AddForce(Vector3.forward * speed);
}
}
}
This is the script I am using to fire a gun. “bullet” is a sphere, with a rigidbody component. The Rigidbody has useGravity and isKinematic off. When I click the mouse button, a sphere is spawned, but just floats there, unmoving. If I spawn another sphere overlapping the first, they both begin to move, floating off into space. This happens regardless of the number I assign as “speed”, whether it’s 100 or 1000000000.