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

Bug Problem with Polygon Collider 2D.

Discussion in 'Scripting' started by melinamelinagutierrez, Oct 11, 2022.

  1. melinamelinagutierrez

    melinamelinagutierrez

    Joined:
    Sep 11, 2020
    Posts:
    2
    Hi everybody,

    I've made a platformer game and since the platforms I'm using are a little bit complex, I decided to use the polygon collider and it works just fine except for one thing. When my player hits an "edge", it makes my player "fly" or bounce and I don't know what's causing this or how to fix this :C

    I'm uploading a gif so you can see what I mean


    Thanks!
     
  2. RadRedPanda

    RadRedPanda

    Joined:
    May 9, 2018
    Posts:
    1,596
    Well, it's pretty clear that it's because you're forcing the object into the side, and the normal force is pushing it up. You probably want to write some code to "magnet" them to the top of the collider when they're going up a slope.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,620
    I must be going blind or something; which part of the GIF shows the problem. I see it jumping twice, which is supposed to be caused by Unity? Neither of those would be caused by the physics engine when something is overlapped. More likely you applying forces in your scripts but it's hard to tell from the GIF.

    Either way, Unity Colliders don't even exist in the low-level engine where this happens, only four primitive shape types do (Circle, Capsule, Convex Polygon and Edges) but more importantly, "colliders" don't impart impulse/forces, the physics solver does when things are overlapped but not like the above!

    Also, so you know, there's dedicated forums for 2D physics you should feel free to use. This forum is obviously for scripting questions.

    https://forum.unity.com/forums/2d.53/
    https://forum.unity.com/forums/physics.78/
     
  4. melinamelinagutierrez

    melinamelinagutierrez

    Joined:
    Sep 11, 2020
    Posts:
    2
    Thanks, I'll be cheking thos forums and see if I can find something there. The jumping that shows in the gif, it's not because I'm making it jump, it does it by itself and that's the issues that I'm having. I don't know if you've noticed but at 5.70 it "jumps" when my player hits that edge.
     
  5. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,620
    I've never encountered anything like that. The only reason that can occur is if a crazy high mass was to happen relative to the body mass. Either crazy small mass and high forces from gravity etc. Is this with stock settings in 2D physics? I'd like to see a repo of this is you could host it somehow.

    If you have no way to host it then please DM me with your email and I can set-up a private repo you can upload a simple project too if you like.

    EDIT: I've noticed you've got very, very small scales here such as 0.05 so the collider is going to be scaled down a lot. Not sure what the size of the collider is you're using here but it'll be 0.05 less than whatever you've set. That's likely to be related to it. These are not just numbers for visuals, they mean something to physics.