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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Converting from 3D collision to 2D

Discussion in '2D' started by artician, Feb 23, 2015.

  1. artician

    artician

    Joined:
    Nov 27, 2009
    Posts:
    343
    Hi,

    I have a functional prototype of a 2D/side-scrolling game that works using 3D colliders. I need it to utilize only 2D physics components though. This is the first time I've worked with Unity's 2D physics system and I seem to be missing something.
    The setup: Each dynamic object in the project has a Box Collider, Rigidbody and Fixed Joint (for manipulation).

    The change: I switched these out for Box Collider 2D, Rigidbody 2D, and a Slider Joint.

    The problem: All my colliders now immediately fall to the ground, through one another and the boundary collision (they fall through the floor and offscreen). Everything in the project is now using 2D components instead of 3D, and nothing else has changed.

    What am I missing?

    Thank you!
     
  2. Senladar

    Senladar

    Joined:
    Jan 1, 2015
    Posts:
    45
    Did you update your code that controls everything? 2D stuff uses all different functions/variables (i.e. Physics2D vs. Physics)
     
  3. codeedward

    codeedward

    Joined:
    Dec 19, 2014
    Posts:
    93
    Yeap @Senladar is right.
    For example:
    OnCollisionEnter(Collision) to OnCollisionEnter2D(Collision2D)

    So more check Your Physics2DSettings is everything ok. Edit -> Project Settings -> Physics 2D
     
  4. artician

    artician

    Joined:
    Nov 27, 2009
    Posts:
    343
    Actually, I think it was the slider joint. In the 3D setup I was freezing the rigidbodies in all axes but the one it was supposed to move in, and using a fixed joint to drag it along that path.
    In the 2D implementation I'm unable to freeze the rigidbody translation axes, and because the joint is only active when the user interacts with it, it didnt have anything to keep it in place in the meantime.

    Thank you for the replies!