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
  4. Dismiss Notice

Reasons for object getting stuck (2D)?

Discussion in 'Physics' started by rh_galaxy, Jun 11, 2022.

  1. rh_galaxy

    rh_galaxy

    Joined:
    Jan 13, 2019
    Posts:
    8
    I have a static cave outline as an array of EdgeCollider2D components.
    I have a space ship with a PolygonCollider2D in the shape of a triangle and a RigidBody2D.
    I move the ship with AddForce(), I rotate the ship with MoveRotation().
    Collision Detection Continuous, Interpolate. Contact Offset 0.001. Fixed Timestep 0.01.

    Sometimes the ship gets stuck with its pointy end in the wall... It can happen both when I run fast into the wall or slow. It doesn't happen often. I think it is happening more often on Unity 2021.1.6f1 than 2019.2.10f1. It happens on 60fps Windows as well as 90fps VR device.
     
    Last edited: Jun 11, 2022
  2. rh_galaxy

    rh_galaxy

    Joined:
    Jan 13, 2019
    Posts:
    8
    1. It works now when I did this:

      Code (CSharp):
      1.  //setting edgeRadius on all EdgeCollider2D
      2. EdgeCollider2D[] mapColliders = gameObject.GetComponents<EdgeCollider2D>();
      3. for (int i = 0; i < mapColliders.Length; i++)
      4. {
      5.      mapColliders[i].edgeRadius = 0.000002f;
      6. }
      7. //setting Physics2D parameters
      8. Physics2D.maxAngularCorrection = 360f; //not sure if needed
      9. Physics2D.maxTranslationSpeed = 0.05f;
      10. Physics2D.maxRotationSpeed = 90f; //not sure if needed
      Maybe someone can explain edgeRadius, what it does for collision detection, and why it helps.
      Also I have a small scale of my world, because you are supposed to use 1 unit = 1 meter in VR.