Ok, so I’ve created a script that instantiates a bullet near the character, however when I set the rigidbody of the bullet to be kinematic the force doesn’t apply and it just sits there (my game has no gravity). The reason why I want it to be kinematic is because otherwise it doesn’t collide with objects properly and has a chance to ghost through them.
This is the code I’m using:
public GameObject Missile = null;
public GameObject MissileS = null;
public GameObject MissileH = null;
public GameObject Launcher = null;
public GameObject Launcher2 = null;
public GameObject Launcher3 = null;
public GameObject LauncherH = null;
public float missileSpeed = 500.0f;
public float fireRate = 0.1f;
public float nextFire = 0.0f;
// Update is called once per frame
void Update () {
if (Input.GetButton("Fire1") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
GameObject launch = GameObject.Instantiate(MissileS, Launcher.transform.position, transform.rotation) as GameObject;
launch.rigidbody.AddRelativeForce(Vector3.left * missileSpeed * 2);
GameObject launchr = GameObject.Instantiate(MissileS, Launcher2.transform.position, transform.rotation) as GameObject;
launchr.rigidbody.AddRelativeForce(Vector3.left * missileSpeed * 2);
}
if (Input.GetButtonDown("Fire2") && Time.time > nextFire)
{
nextFire = Time.time + fireRate;
GameObject launchs = GameObject.Instantiate(Missile, Launcher3.transform.position, transform.rotation) as GameObject;
launchs.rigidbody.AddRelativeForce(Vector3.left * missileSpeed * 3);
}
if (Input.GetButtonDown("Fire3") && Time.time> nextFire)
{
nextFire = Time.time + fireRate;
GameObject launchH = GameObject.Instantiate(MissileH, Launcher3.transform.position, transform.rotation) as GameObject;
launchH.rigidbody.AddRelativeForce(Vector3.left * missileSpeed * 3);
}
}