Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

How to make collision between 2 objects?

Discussion in '2D' started by iRemains, Jan 14, 2016.

  1. iRemains

    iRemains

    Joined:
    Jan 14, 2016
    Posts:
    2
    Hello,
    With friend, we create a ittle game where you control a boat and you must avoid stone, but we don't understand how we can detect the collision and make losse the game?

    I upload screenshot of these two object (boat and stone) we work on 5.0.2f3
     

    Attached Files:

  2. FyreDogStudios

    FyreDogStudios

    Joined:
    Aug 23, 2015
    Posts:
    97
    If you have colliders of the same type (2d/3d) on both objects, they should collide fine.

    Then you have access to OnCollisionEnter / OnCollisionEnter2D, this is where you can detect what hit your player.

    eg.

    Code (CSharp):
    1. void OnCollisionEnter2D(Collision2D col){
    2. Debug.log("Collided with " + col.gameObject.name);
    3.  
    4. }
     
    iRemains likes this.
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Take time to do the tutorials in the learn section linked at the top. They will explain how to use colliders & triggers. After you complete each one start a new project & try to do it on your own to highlight the bits you need for revision. Then try to add something to the game or change bits to see what effects they have. This is the best way to learn.
     
  4. iRemains

    iRemains

    Joined:
    Jan 14, 2016
    Posts:
    2
    It's for school, it's a "game of entreprise" and we need to make communication so we create website, audio adds, and a game but we only have 2days