Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Issue with Rigidbody2D

Discussion in '2D' started by dirtycharly, Jan 9, 2016.

  1. dirtycharly

    dirtycharly

    Joined:
    Jan 9, 2016
    Posts:
    3
    hello, I don't understand why this line doesn't work :

    I'm watching a tutorial of how to create a little game and i want my png to jump ! but this is the first time I use code or even unity... so I quiet lost. thanks for your help ! Capture d’écran 2016-01-10 à 00.41.37.png Capture d’écran 2016-01-10 à 00.41.51.png
     
  2. Manato

    Manato

    Joined:
    Jun 11, 2015
    Posts:
    28
    You have to attach a rigidbody2D on you game object and in your script you need a reference of that rigidbody2D.
    Code (JavaScript):
    1.  
    2.  
    3. rig : Rigidbody2D;
    4.  
    5. function Start(){
    6.     rig = GetComponent("Rigidbody2D");
    7. }
    For this example you can use addForce on rig in your update function.
     
  3. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    I'd suggest doing the official unity tutorials if you aren't already. They will likely be more updated than others you may find.
     
  4. KevG

    KevG

    Joined:
    Oct 4, 2015
    Posts:
    20
    Also the first warning is telling you that what you are coding in using obsolete code.
    Check the new way of coding.

    Just something I noticed in the error list