Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

How can I make simple 2D Collision

Discussion in 'Project Tiny' started by silverduck, Jan 30, 2021.

  1. silverduck

    silverduck

    Joined:
    May 16, 2010
    Posts:
    27
    What's the simplest way to create 2D colliders that will stop the player? Is there a good example available?

    I'm trying to make a game that involves what's basically a top-down view of a character navigating a simple maze. Currently I have inputs that move the player by adding to his position in the Translate component and I've tried all sorts of combinations of adding 2D Rigidbodies and Physicsbodies and 2D Colliders and Physics shapes and even turning on gravity and just letting my character "fall" but nothin I seem to do stops the player from just passing freely through everything.

    The Spaceship example seems to be the closest I get but it only uses collision to destroy things or stop the game and never actually has anything stop anything else from moving.

    Is there a simple way to create walls that a player can't go through or do I need to do something like using the hit detection to stop the player programatically?
     
  2. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Hello @silverduck,
    The 2D Entities Physics package does not contain any collision response. This is something you have to implement yourself. You could also switch to 3D physics (com.unity.physics) if you would like to use already implemented collision response.
     
  3. silverduck

    silverduck

    Joined:
    May 16, 2010
    Posts:
    27
    I did wind up making my own 2D collision implementation based on the Spaceship Demo but with a bit more logic. One thing that really tripped me up for a long time was that one object would give very strange collision results. Sometimes only colliding with itself constantly and sometimes colliding with nothing ever, based on small changes I made but couldn't figure out any pattern.

    Ultimately the problem was solved when I set the scale of the object with the collider from (.05,.05,.05) back to (1,1,1) and put its sprite renderer on a child object which I then scaled accordingly. I don't know if this was a bug or just some intended side effect that I don't understand.
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,456
    If you do suspect a bug then it'd be great if you could submit a bug report for this with a simple reproduction.

    Thanks!
     
  5. nukadelic

    nukadelic

    Joined:
    Aug 5, 2017
    Posts:
    78
    Any updates on that ? Kinda strange to have an engine without collision response
     
  6. Ted_Wikman

    Ted_Wikman

    Unity Technologies

    Joined:
    Oct 7, 2019
    Posts:
    916
    Currently we do not have any news to share regarding the collision response in the 2D Entities Physics package.