var target : Transform;
var prefabBullet : Rigidbody;
var shootForce;
var range = 10;
var LastFired = 0.0;
function Update () {
if((Time.time > LastFired +1.0) (Vector3.Distance(transform.position, target.position) < range))
{
Instantiate(prefabBullet, transform.position, Quaternion.identity);
prefabBullet.rigidbody.AddForce(transform.forward * shootForce);
}
}
I want the turret to shoot once a second, help 
var shootInterval = 1.0;
function Start () {
InvokeRepeating("Shoot", shootInterval, shootInterval);
}
function Shoot () {
// do shooty stuff here
}
–Eric
It works!, Thanks alot, the only problem is, For some reason there is no force behind the bullet, it just falls out of the cannon
var shootInterval = 0.5;
var range = 10;
var shootForce = 50;
var prefabBullet : Rigidbody;
var target : Transform;
function Start () {
InvokeRepeating("Shoot", shootInterval, shootInterval);
}
function Shoot ()
{
if((Vector3.Distance(transform.position, target.position) < range))
{
Instantiate(prefabBullet, transform.position, Quaternion.identity);
prefabBullet.rigidbody.AddForce(transform.forward * shootForce);
}
}
Help?
Use ForceMode.Impulse, or .VelocityChange.
–Eric
I can’t find anythin on VelocityChange, or Mode.Impulse, Can you give me a example on how it works?, i’m still new to this
Look up AddForce in the docs.
–Eric
SOrry, i’m not finding anything, Can you give me a example?
Unity - Scripting API: Rigidbody.AddForce You can see that ForceMode.Force is the default, so add ForceMode.Impulse instead.
–Eric
var booon = Instantiate(LaserBullet, transform.Find(“LaserBulletSpawnPoint”).transform.position, Quaternion.identity);
booon.rigidbody.AddForce(transform.forward * 4500);
This will shoot the bullet out quite fast from a “LaserBulletSpawnPoint”