Invalid Cast Exception

I am working on what should be a simple instantiate script for firing a projectile.

I have used this syntax before without issue but I cannot get this to run properly. I keep getting an invalid cast exception but as far as I can tell I am keeping the type as a rigidbody.

It is the same code used in the FPS tutorial. I know certain parts are out-of-date but I thought this was still valid.

At this point the script creates instances but they have no velocity.

private var fireDist = 15;
var projectile : Rigidbody;
var fireRate = 0.5;
private var nextFire = 0.0;

function Update () {
	var jeepGO = GameObject.FindWithTag("jeep");
	var jeep = jeepGO.transform;
	var dist = Vector3.Distance(jeep.position, transform.position);
	
	if (dist < fireDist  Time.time > nextFire) {
        nextFire = Time.time + fireRate;
  		var bullet : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
		bullet.velocity = transform.TransformDirection (Vector3.up * 100);
    }
	
}

Any help is greatly appreciated,

Kevin

If you had projectile defined as some type other than Rigidbody before, try setting it to None in the inspector, and then dragging the prefab onto the slot again.

–Eric

Eric,

That did the trick - thanks!

Kevin