Search Unity

Problem with rb2d forces on edge collider (pic included)

Discussion in '2D' started by Jqob, Feb 21, 2019.

  1. Jqob

    Jqob

    Joined:
    Dec 20, 2018
    Posts:
    35
    I have a problem with rb2d.AddForce

    I want my ball to jump vertically whenever it collides with my edge collider. However when it lands just on the edge of the collider, the force doesn't go vertically but rather in an angle ( see pic below for visualization).

    Basically green ball is behaving correctly, while red is not.
    Help?
     

    Attached Files:

  2. ManiaCCC

    ManiaCCC

    Joined:
    Aug 15, 2015
    Posts:
    41
    can you post code, how you call addForce? It will tell us more

    You have something like OnCollisionEnter simple addForce line? (like in the picture?)
     
  3. Jqob

    Jqob

    Joined:
    Dec 20, 2018
    Posts:
    35
    Yes, OnCollisionEnter, check game tag of the object, if platform - AddForce(Vector2.up * 2000)
     
  4. Jqob

    Jqob

    Joined:
    Dec 20, 2018
    Posts:
    35
    Bump
     
  5. Jqob

    Jqob

    Joined:
    Dec 20, 2018
    Posts:
    35
    Edit: Okay, I just noticed this only occured when I'm using Accelometer for horizontal controls. Whenever I use keyboard for X-axis movement it works fine, but when I switch to acceleration, it starts bouncing off to the side whenever the ball hits the edges. Can someone help me fix this?