Problem with instanciating

Hi there. Sorry to bother you with my stuff, but I cannot solve the Problem by myself. I try to instanciate a Fireball for my Wizard. But the Game always interrupts my script before LogPoint 2:

var projectile : Rigidbody;
var speed : int = 800;

function Update () {
	if ( Input.GetButtonUp("Fire1") )
	{
		// Instance and give godspeed
		var myInstance : Rigidbody;
		Debug.Log("1");
		myInstance = Instantiate(
						projectile, transform.position, transform.rotation);
		
		Debug.Log("2");				
		myInstance.velocity = 
			transform.TransformDirection( Vector3( 0, 0, speed ) );
			
		// Turn off collision with player
		Debug.Log("3");
		Physics.IgnoreCollision( myInstance.collider, transform.root.collider );
	}
}

I have tried to set projectile to GameObject and modified the second Line according to it (gameObject.rigidbody.velocity) but the error remains. There are several threads about it on the forums, but I was unfortunately not able to solve it by reading those threads. The solutions there did not work. This sample is from the fps-tutorial, so I assumed it worked.

The message:

Hmm I just attached the script to an object and attached a object with a rigidbody and no problem here…
Are you sure that the gameobject you attach has a rigidbody?

Thanks for your answer just solved it momentarily :smile:.

var projectile : GameObject;
var speed : int = 800;

function Update () {
	if ( Input.GetButtonUp("Fire1") )
	{
		// Instance and give godspeed
		var myInstance : GameObject;
		Debug.Log("1");
		myInstance = Instantiate(
						projectile, transform.position, transform.rotation);
		
		Debug.Log("2");				
		myInstance.rigidbody.velocity = 
			transform.TransformDirection( Vector3( 0, 0, speed ) );
			
		// Turn off collision with player
		Debug.Log("3");
		Physics.IgnoreCollision( myInstance.collider, transform.root.collider );
	}
}

That works, except that the Fireball does not fly exactly to where I want (along the z-coord of the view), but I think its a problem of my TransformDirection. And yes, the object attached to the script has a rigidbody :).
Thanks.

Haha nice :slight_smile: