- Home /
 
               Question by 
               heaversm · Jul 13, 2011 at 06:22 PM · 
                collisionraycastprojectilechildren  
              
 
              ignore ray collision with game object children
Hey - I have a script set up to shoot rays into the scene. I want them to ignore the walls of my scene, which I have assigned a tag called Walls. Here's my script: I'm not sure why it's not working. I get the error "object reference not set up to an instance of an object".
 var projectile : Rigidbody;
 var speed = 20;
 var boundaryRef;
 
 function Start(){
     boundaryRef = GameObject.FindGameObjectsWithTag ("Walls");
 }
 
 function Update()
 {
     if( Input.GetButtonDown( "Fire1" ) ){
         //instantiate a projectile and throw it toward the cube (x axis)
         var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation ) ;
         instantiatedProjectile.velocity = transform.TransformDirection( Vector3( speed, 0, 0) );
         Physics.IgnoreCollision( instantiatedProjectile.collider, boundaryRef.collider); //make sure to ignore collision between launcher and missile
     }
 };
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by heaversm · Jul 13, 2011 at 08:11 PM
I figured it out. This is probably not the best way to do things, but I realized that boundaryRef creates an array, so I had to change my code to loop through the array and ignore:
 for (var i=0; i<boundaryRef.length;i++){
             Physics.IgnoreCollision( instantiatedProjectile.collider, boundaryRef[i].collider); //make sure to ignore collision between launcher and missile
         }
Answer by DaveA · Jul 13, 2011 at 07:38 PM
You don't want to put your walls in the 'ignore raycast layer'?
Are you sure you're getting anything back from FindGameObjectsWithTag?
Did you assign something to projectile in the Inpector or other code?
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                