Search Unity

2D Collision on specific area of a sprite

Discussion in '2D' started by kyuzki, Mar 22, 2017.

  1. kyuzki

    kyuzki

    Joined:
    Mar 22, 2017
    Posts:
    3
    I am new to unity. Just started reading some tutorials yesterday. I'm trying to make a certain object in the game have a collision point on a certain area of it (ex: the twigs of a tree). But have no idea how to do this. Help please? :)
     
  2. webox

    webox

    Joined:
    Aug 27, 2015
    Posts:
    72
    Hi! What you're looking for are called colliders, in particular colliders2D. Colliders are components you add to your game objects. There are several types of colliders and each one can be edited by using the edit collider button, present in the Explorer. Using this functionality you can adjust the collision points at your will
     
  3. kyuzki

    kyuzki

    Joined:
    Mar 22, 2017
    Posts:
    3
    so its ok to remove the Rigid Body 2D component and my obstacles will still work?
     
  4. webox

    webox

    Joined:
    Aug 27, 2015
    Posts:
    72
    Rigid bodys are use to provide physics properties to your game objects. Colliders are used to detect collision areas and can be used with or without RB. When you remove a rigid body but keep the collider, the object becomes static, meaning that it can collide with other objects but it won't be affected by physics.
     
  5. kyuzki

    kyuzki

    Joined:
    Mar 22, 2017
    Posts:
    3
    hmm..I need the RB so I can have the object move. I'm using the flappy bird game as my basis for study btw.

    u3d.png

    as seen in the image, I am trying to just make the green area of the building have the collision as I want the obstacles be the windows generated at random locations of the building(still working on the randomized location). So when the position of the green part changes, the collision are changes as well
     
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,500
    To be clear, "physics" isn't collision response so all colliders are always affected by "physics".

    A Collider2D will try to attach to a Rigidbody2D on the same GameObject or on a parent GameObject. If no Rigidbody2D is found then the Collider2D is known as a Static Collider2D and should not be moved.

    When you add a Rigidbody2D you are asking for it to update the Transform component with forces that get applied to it. Forces that can get applied to it are gravity, forces you apply or forces the colliders attached to it apply when they contact other colliders.