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.

Physic to 2D

Discussion in 'Physics for ECS' started by gato0429, Mar 10, 2022.

  1. gato0429

    gato0429

    Joined:
    Mar 5, 2015
    Posts:
    21
    How are you,

    I'm doing a 2d project, and using dots and ecs, but got to the point of collisiones, and found physics, but this works for 3d, and the physics2d project is linked to tiny project. My question is if someone adapted physic to work in a 2d environment. Since I tried to use a shape box, but without depth (Z=0). (Work only with X Y coordinates), but when using a dynamic body it does not collide with other objects that have Z=0. But if I place an object with Z <> 0, I do find a collision. Would I have to freeze any axis? or any idea how to emulate collisions in 2d.

    Thanks in advance.
     
  2. JosepMariaPujol

    JosepMariaPujol

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    77
    A short hack would be to freeze the tensors of inertia to zero in the X, Y-axis (or whatever plane you choose to work on) and add a system to reset the one locked linear axis in the Translation component to zero.
     
  3. JosepMariaPujol

    JosepMariaPujol

    Unity Technologies

    Joined:
    Jun 16, 2021
    Posts:
    77
    Also, you can use the old Physics Components such as RigidBody(3d) and BoxCollider(3d) and freeze the axis you want to make your game behave as if it was a 2D game. Remember: you will have to add them into a SubScene or toggle the button "Convert to Entity" to benefit the UnityPhysics engine.
     
  4. gato0429

    gato0429

    Joined:
    Mar 5, 2015
    Posts:
    21
    Thank you for your answer, I will put into practice what you indicate. regards