Search Unity

Quick rigid body question from totally new user

Discussion in 'Community Learning & Teaching' started by timmybizz, Sep 30, 2015.

Thread Status:
Not open for further replies.
  1. timmybizz

    timmybizz

    Joined:
    Sep 30, 2015
    Posts:
    3
    Trying to learn Unity, however the tutorials I am watching are pre Unity 5 and don't cover how to properly deal with the new Rigidbody setup.

    Simple script that I can't figure out the error, please advise.

    usingUnityEngine;
    usingSystem.Collections;

    publicclassBasic_Move : MonoBehaviour
    {
    publicfloatspeed = 3.0f;
    publicfloatjumpSpeed = 20.0f;

    //Usethisforinitializationthisisjustacomment
    voidStart ()
    {


    }

    //Updateiscalledonceperframe
    voidUpdate ()
    {
    Vector3x = Input.GetAxis ("Horizontal") * transform.right * Time.deltaTime * speed;
    Vector3z = Input.GetAxis ("Vertical") * transform.forward * Time.deltaTime * speed;

    transform.Translate (x + z);
    }

    voidFixedUpdate()
    {



    if (Input.GetKeyDown ("Jump"))
    {
    Jump();
    }

    }

    voidJump()
    {
    GetComponent<Rigidbody>().addForce(Vector3.up * jumpSpeed);
    }

    }
     
  2. timmybizz

    timmybizz

    Joined:
    Sep 30, 2015
    Posts:
    3
    it took out some formatting from copy and paste, but i am assuming that whoever can help me with this will recognize that. any help in the right direction is greatly appreciated. just an artist trying to learn to code, danke
     
  3. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    Wrap the code in Code/Code tags (with [ ] around each) to preserve the formatting, what errors are you getting?
     
  4. timmybizz

    timmybizz

    Joined:
    Sep 30, 2015
    Posts:
    3
    @MikeUpchat This error:

    Assets/Scripts/Basic_Move.cs(39,43): error CS1061: Type `UnityEngine.Rigidbody' does not contain a definition for `addForce' and no extension method `addForce' of type `UnityEngine.Rigidbody' could be found (are you missing a using directive or an assembly reference?)


    Thank you sir
     
  5. MikeUpchat

    MikeUpchat

    Joined:
    Sep 24, 2010
    Posts:
    1,056
    Use an uppercase 'A' in AddForce
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you please learn to use code tag properly?

    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  7. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
Thread Status:
Not open for further replies.