2
votes

I'm creating a fast-paced, 2D side-scrolling game on Unity 5.2, building my terrain out of discrete "blocks", each with its own EdgeCollider2D component.

Having a problem where my character gets bumped upward as it crosses from one block to another (imagine driving your car over a speed bump on the road).

This doesn't happen all the time. Seems to be random, which is even more irritating, as it makes finding a solution more difficult.

I've tried all of the suggestions that I could find for similar questions on this site, including:

  • Using CircleCollider2D's on the character
  • making sure the terrain blocks and their corresponding colliders are perfectly aligned. The attached screenshot shows one of the intersections.
  • changing the "Min penetration for penalty" setting to the minimum allowed value (0.0001)
  • switching between discrete and continuous collision detection for the character's RigidBody2D
  • increasing the mass and gravity scale for the character's RigidBody2D

... to no avail.

Beyond building a single, massive terrain object with a single edge collider from start to finish (which I'm trying to avoid), I've run out of ideas. Anything else I'm missing? Is it just a Unity bug?

Help!

Terrain block intersection screenshot - zoomed in

Zoomed out - scene

1
Not uh...100% sure what your image represents. Looks like just a screenshot of an orthographic viewport...with an object in half the view?Serlite
@Serlite It's a zoomed-in (and cropped) screenshot of where two terrain blocks and their colliders intersect - to show they are (all) perfectly aligned. I've edited the question and added a second, zoomed-out screenshot hoping that makes it clearer.nerv
@user3071284 yes. I have used Vertex snapping and also typed in all transport and collider points (via script) to ensure they line up.nerv
Try changing to 3D/perspective camera and see if you can zoom in any further; sometimes I find the orthographic camera might not zoom in as far. Is the bumping happening between all blocks or just the ones that aren't flat?user3071284

1 Answers

0
votes

Try detect the collision and set the vertical velocity to zero.

void OnCollisionEnter2D(Collision2D col)
{
    if (col.gameObject.name.StartsWith("block"))
        rigidbody2d.velocity = new Vector2(rigidbody2d.velocity.x, 0);
}