Unity controls the movement of 2D objects, but the 2D collider Box Collider has no effect.

First, add a 2D rigid body and 2D collider to the protagonist. In order to prevent the protagonist from being affected by gravity, set the Body Type property of the 2D rigid body to Kinematic kinematics, and add a 2D collider to the objects that need to collide.

After the preparations were completed, I controlled the movement of the protagonist but found that the desired collision effect was not produced, and the protagonist could still pass through objects with colliders.

My solution is to set the Body Type property to Dynamic. Although it will be affected by gravity, you can set its weight to 0.0001 and the resistance to 1000. The resistance can be adjusted according to the situation, as long as it feels unaffected by gravity. The effect is enough.

This achieves the effect I want. Hope this tip can help someone in need.

Guess you like

Origin blog.csdn.net/qq_41556243/article/details/124530130