Unity 2D Collider

1. What is a collider?

A collider is a (shape or range) rigid body used to represent the volume of an object in a physical system. It is
calculated by obtaining the range information of the collider
to determine whether the range of two objects are in contact.
If the rigid body is in contact, the effect of the force will be simulated to generate speed and rotation.

2. Parameters

Edit Collider: Edit Collider

Material: a physical material used to determine the properties of collision, control friction and elasticity
Is Trigger: whether it is a trigger
Used By Effector: whether it is used by an attached 2D effector

Used By Composite: Attach a collider to a 2D composite collider

Auto Tiling: When the DrawMode in SpriteRenderer is Tile tiling mode, the collider will follow the size change of the sprite.

Edge Radius: Make corners rounded

3. Composite collider parameters

(1) Geometry Type: Geometry type. When merging colliders, the vertices of the colliders will be combined into two different geometry types.

Outlines: hollow outlines, similar to boundary colliders
Polygons: solid polygons, similar to polygon colliders

(2) Generation Type: Generation type, when the composite collider generates new geometry

Synchronous: When modifying the 2D compound collider or other collider used, Unity immediately generates new geometry.
Manual: Manually generates new geometry, either through code generation or by clicking the issued Regenerate Geometry generation button.

(3) Vertex Distance: The minimum spacing value allowed when collecting vertices from a composite collider

4. Collision detection function

    private void OnCollisionEnter2D(Collision2D collision)
    {
        //进入碰撞
    }

    private void OnCollisionExit2D(Collision2D collision)
    {
        //退出碰撞
    }

    private void OnCollisionStay2D(Collision2D collision)
    {
        //碰撞中
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        //触发
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        
    }

    private void OnTriggerStay2D(Collider2D collision)
    {
        
    }

 

Guess you like

Origin blog.csdn.net/holens01/article/details/130842668