nerv
nerv

Reputation: 21

Unity 5.2 - Moving character bumps between 2D edge colliders

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:

... 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

Upvotes: 2

Views: 1449

Answers (1)

Frank Herbert
Frank Herbert

Reputation: 1

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);
}

Upvotes: 0

Related Questions