Search Unity

Roll-a-ball

Discussion in 'Getting Started' started by Prdelka, Apr 16, 2015.

  1. Prdelka

    Prdelka

    Joined:
    Apr 16, 2015
    Posts:
    1
    Hello, Im tryin unity for the forst time and I started with making Roll-a-ball project acording official tutorial. I stacked at moving the ball...

    using UnityEngine;
    using System.Collections;

    public class PlayerController: MonoBehaviour
    {
    public Rigidbody playerRigidBody;


    void Fixedupdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");

    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    playerRigidBody.AddForce (movement);

    }
    }

    The ball doesnt move...
    pls help
     
  2. Mister_Potter

    Mister_Potter

    Joined:
    Apr 16, 2015
    Posts:
    2
    You need to change your function's name to FixedUpdate () instead of Fixedupdate().
     
  3. kdubnz

    kdubnz

    Joined:
    Apr 19, 2014
    Posts:
    177
    Also,
    Where is playerRigidBody assigned a value ??
     
  4. Simpso

    Simpso

    Joined:
    Apr 20, 2015
    Posts:
    158
    As above you havent assined Rigidbodyplayer a value. So at the moment you are asking addforce to use Rigidbodyplayer as a ridigidbody without calling the component for Rigidbody.

    Try entering this code above FixedUpdate() << don't forget to caps the U in update

    Code (csharp):
    1. void Start()
    2. {
    3.       playerRigidBody = GetComponent<RigidBody>();
    4. }
    5.  
    Hopefully this will fix your issue.
     
    Last edited: Apr 20, 2015
  5. Mister_Potter

    Mister_Potter

    Joined:
    Apr 16, 2015
    Posts:
    2
    He's using a public variable for rigid body. You can assign it from outside the script.
     
  6. kdubnz

    kdubnz

    Joined:
    Apr 19, 2014
    Posts:
    177
    No. He is using a public declaration. ( which just determines a memory placeholder for a variable)
    I asked how/where he was assigning a value to that field.
     
  7. GSteele

    GSteele

    Joined:
    Feb 4, 2015
    Posts:
    9
    By dragging the ball/object into the form field in the properties panel
     
    Sylvir likes this.
  8. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    were you able to get the ball moving or are you still looking for some help?
     
  9. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Also for the tutorials that the learn team put up there is Q&A threads under the teaching section made for each specific tutorial. Makes it alot easier for the tutors to find posts related to their tutorials :)

    have a look over at the RollABall Q&A thread if need further info.
    http://forum.unity3d.com/threads/roll-a-ball-tutorial-q-a.319451/