Search Unity

Rigidbdy2D.velocity.y

Discussion in '2D' started by slimskan, Sep 22, 2018.

  1. slimskan

    slimskan

    Joined:
    Sep 22, 2018
    Posts:
    2
    Hi Guys,
    I just want to know if it possible in the newer version of Unity to set the Y velocity of a Rigibody2D such as :
    Rigidbdy2D.velocity.y = 0;
    I always get the following error message :


    error CS1612: Cannot modify a value type return value of `UnityEngine.Rigidbody2D.velocity'. Consider storing the value in a temporary variable


    Thanks for the help !
     
  2. vakabaka

    vakabaka

    Joined:
    Jul 21, 2014
    Posts:
    1,153
    try:
    Rigidbdy2D.velocity = new Vector2 (Rigidbdy2D.velocity.x, 0);
    or as error says, use
    Vector2 tmpVector = new Vector2 (something, something):
    Rigidbdy2D.velocity = tmpVector;
     
    slimskan and MoonJellyGames like this.
  3. slimskan

    slimskan

    Joined:
    Sep 22, 2018
    Posts:
    2
    Thanks for the help, will try it and give you feedback !