Search Unity

Box collider 2d collision help

Discussion in '2D' started by JackAshwell, Nov 9, 2019.

  1. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    So here is my current code:
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Collision : MonoBehaviour
    7. {
    8.     void OnTriggerEnter2D(Collider2D other) {
    9.         Debug.Log("TRIGGER");
    10.     }
    11. }
    12.  
    And my unity inspector:
    https://imgur.com/a/2WimZ2J



    So when i go to run Unity, it doesn't show up the 'TRIGGER' log in the console.

    If anyone knows what's wrong, it would be greatly appreciated!

    Thanks!
     

    Attached Files:

    Last edited: Nov 9, 2019
  2. mystrymaster

    mystrymaster

    Joined:
    Oct 30, 2019
    Posts:
    6
    What is the exact problem here?
     
  3. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    I edited the problem in there
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @JackAshwell

    BTW I think adding feedback tag means you are trying to give feedback / report some Unity feature related issue - which you are not doing here... you are just asking a question. It shouldn't be used to catch attention...
     
  5. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    Oops, my bad. I'm kinda new to unity, sorry.
     
  6. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    BTW you can attach images permanently to forum posts, using "Upload a File" button next to "Post Reply" button.

    Now your Imgur link works (site which I don't usually visit, the whole site is annoying) but your images on your post are broken.
     
  7. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    My bad again
     
  8. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @JackAshwell

    If you are using physics2D (like you seem to be using), when one object has collider, and another has collider + rigidbody2D, you should be good to go, even if both are set to be triggers.

    But seems like you have set your Pac-man to "Pacman" layer, and your walls to "Wall" - have you made sure, that Pac-man and walls layers are checked in collision matrix of Physics 2D settings? Otherwise those layers wouldn't register hits between each other...

    Also, I won't start guessing more, but you didn't even actually mention which objects don't collide... Pac-man vs walls, or Pac-man vs coins??

    Also, can't see Pac-man rb settings - and walls probably don't need rb as those are static / non-moving in Pac-man.

    You should try to explain all the steps you have taken, otherwise readers will be just guessing what you have done or not done.
     
  9. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    The pacman, walls and coins are all checked in the collision matrix so they are fine.

    I wanted the pacman and walls as well as the pacman and coins to collide so i can then add points to the player.

    Also i have the coins, pacman and the walls all as static.


    Sorry if i wasn't too detailed, this is my first game that i'm making on my own.
     
  10. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    @JackAshwell

    Pac-man is moving and colliding, it shouldn't be static.

    Also, coins too shoudn't be static - make then have no gravity instead as Pac-man is top down game.
     
  11. JackAshwell

    JackAshwell

    Joined:
    Oct 21, 2019
    Posts:
    24
    So i made pacman and the coins dynamic with no gravity, but it still doesn't work.
     
  12. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    I can't help much more. Maybe there is something else going on.

    I would try to drop your script to new sprite objects in blank scene. Add colliders + rigidbody.

    Then you can manually move two sprites with collider as trigger to overlap, and see if you get the debug message.