I had a working script, then somewhere along the line something got deleted and I cannot figure out how to get back to where is was. I have a driveable tank with a game object attached to the end of the barrel that fires projectiles on a left mouse click. With the following script however, my bullets spawn but dont move. What have I miscalculated?
using UnityEngine;
using System.Collections;
public class fireBullet : MonoBehaviour {
public Rigidbody bullet;
public float cannonPower;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
//fire cannon
if(Input.GetButtonUp("Fire1")){
//create projectile at location script is attached to
Rigidbody instance = Instantiate(bullet, transform.position, transform.rotation) as Rigidbody;
//add force to projectile
Vector3 fwd = transform.TransformDirection(Vector3.forward);
instance.AddForce(fwd*cannonPower);
}
}
}