Search Unity

plz help, how to get an object to freeze in mid air 2D

Discussion in 'Scripting' started by lakiid373, Jun 11, 2019.

  1. lakiid373

    lakiid373

    Joined:
    Jun 11, 2019
    Posts:
    5
    Well the title pretty much speaks for itself,I want when you press a key .the object will freeze in the air at that position until you let down the key.But the problem is that i dont know how to make the object freeze.I tried rb.gravityScale = 0; , and on the rigidbody without 2d i tried rb.useGravity=false; AND it worked but in rigidbody there is no gravity scale pharameter and i need that gravityScale = 2.SO i dont know what to do,here is the beginning of the script; Thx for your time

    private Rigidbody2D rb;
    void Start()
    {
    rb = GetComponent<Rigidbody2D>();
    }
    void Update()
    {
    if (Input.GetKey(KeyCode.Space))
    {

    }
    }
     
  2. lakiid373

    lakiid373

    Joined:
    Jun 11, 2019
    Posts:
    5
    nvm i got it to work
    if (Input.GetKey(KeyCode.Space))
    {
    m_Rigidbody.constraints = RigidbodyConstraints2D.FreezeAll;
    }
    else
    {
    m_Rigidbody.constraints = RigidbodyConstraints2D.None;
    }