Collision problem

Hey, I have the following colliders:


Star is polygon, red one is a polygon, too and a box collider.

It is kind of an obstacle with a top, I want the star to be able to collide with the top but not the body itself, so I gave the obstacle one child with ‘body’ tag and the red polygon on the parent has an obstacle tag.

I catch the collision in OnCollisionEnter2D and then I look what’s been triggered (col.collider.tag). The star moves from the top to the bottom, but somehow sometimes the star touches the body instead, and I don’t know why. The star is a rigidbody and I move it with rigidbody.MovePosition(pos + x), is this why and if so, how could I improve that behaviour?

Yep, you figured it out.

What happens is movePosition is very, very literal. So without very robust checks, it will enter other colliders and fail collision checks. Lame!

Use rigidbody.velocity, instead.

            rb.velocity = new Vector3(Input.GetAxisRaw("Horizontal") * someSpeed * Time.deltaTime, 0f, rb.velocity.z);