Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Capsule Collider 2D

Discussion in '2D' started by DougVTR, Jul 28, 2019.

  1. DougVTR

    DougVTR

    Joined:
    Jul 17, 2019
    Posts:
    1
    I need to know how is the command to change the direction of the collider when pressing the selected key. In case I'm using this to be able to make the character bend over and change his collider together.
    I don't know if this mode I use is correct or not, but I'm in doubt about something simple because I started now and I'm creating my first game.

    My code:
    if (Input.GetKey(KeyCode.C))
    {

    //My question ---- GetComponent<CapsuleCollider2D>().direction = ????
    GetComponent<CapsuleCollider2D>().size = new Vector2(0.2763716f, 0.1033123f);
    crouching = true;
    jumping = false;
    walking = false;

    }
    else if ((Input.GetKeyDown(KeyCode.Z)))
    {

    GetComponent<CapsuleCollider2D>().size = new Vector2(0.203178f, 0.2997613f);
    crouching = false;
     
  2. Proker

    Proker

    Joined:
    Aug 6, 2013
    Posts:
    1
    GetComponent<CapsuleCollider2D>()..direction = CapsuleDirection2D.Vertical;