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

Question why Rigidbidy 2D after setting Body Type Dynamic the player changes position..

Discussion in '2D' started by Ricc3, Aug 29, 2022.

  1. Ricc3

    Ricc3

    Joined:
    Aug 29, 2022
    Posts:
    2
    Hello

    At the outset, sorry for my poor English.. But going to particulars..

    I am a beginner "creator" and I would like to understand why in Rigidbody 2D -> Body Type after selecting Dynamic the character floats on "a few pixels" after turning on the game simulation..

    Is it due to some kind of engine fault? Maybe it can be fixed somehow?

    I will add that when changing to Kinematic and Static, this problem does not occur.

    I am adding screenshots showing what I mean.

    Thank you all for help and all information.
    Sorry again for my poor english.

    Greetings - Ricc3
     

    Attached Files:

  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,622
    Dynamic interacts with the environment so it'll keep itself separated with collision detection and response. Kinematic or Static don't do that. Physics doesn't work in pixels. It keeps a separation between polygons for stability.

    It's not an "engine fault" that needs fixing.
     
  3. Ricc3

    Ricc3

    Joined:
    Aug 29, 2022
    Posts:
    2
    I watched tutorials on YT and it was shown there that one element touches the other .. I do not know if it worked differently in previous versions or simply no one paid attention to it and did not explain it .. I was just scared that something was wrong at my place ..

    anyway..
    I understand and in that case, thank you for your help and some information ..
     
    MelvMay likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,622
    That separation is controlled by: https://docs.unity3d.com/ScriptReference/Physics2D-defaultContactOffset.html

    BUT! Don't go changing it simply because you want that small gap to disappear. Be warned that if you do, you may get poor collision detection for polygons. Of course, if you know what you're doing and/or you test well, it may be fine for your project. If you do change it and get instabilities then consider restoring it back to its default and test again.
     
  5. smallg2023

    smallg2023

    Joined:
    Sep 2, 2018
    Posts:
    103
    where is the green box on the square? are the 2 green lines touching?