Using Tags in Collision

Started by xraybeesx 2 posts 82 views

Reply on sbox.game
  1. #1
    xraybeesx 1,160
    I'm trying to use tags to discern what I'm colliding with, but I can't seem to get it working. I am using:


    void ICollisionListener.OnCollisionStart(Collision collision)
    		
    {
    	
    
    	if ( GameObject.Tags.Has( "friendly" ) )
    	{
    			friends = true;
    	}
    
    	
    }

  2. #2
    Omjihn 855
    Hi, the problem is that GameObject is the current GameObject that has the component attached.

    void ICollisionListener.OnCollisionStart(Collision collision)	
    {
    	if ( collision.Other.GameObject.Tags.Has( "friendly" ) )
    	{
    			friends = true;
    	}
    }

    This fix make sure you retrieve the the other object like this:collision.Other.GameObject.