Search Unity

Official Roll-a-ball Tutorial Q&A

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Apr 17, 2015.

  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is the official thread for discussion, issues and Q&A for the Roll-a-Ball project

    Please use this thread if you have any questions, issues or feedback on this project.

    Roll a Ball is a learning project on our Learn Site:
    http://unity3d.com/learn/tutorials/projects/roll-a-ball

    In your first foray into Unity development, create a simple rolling ball game that teaches you many of the principles of working with Game Objects, Components, Prefabs, Physics and Scripting.

    -

    The Roll-a-ball project has been updated to Unity 5. If you have questions re: the old version for Unity 4, please upgrade both your version of Unity and your project, please.
     
  2. sergi33

    sergi33

    Joined:
    Dec 9, 2013
    Posts:
    1
    Thanks for the update and effort.
     
    Niblo likes this.
  3. 313b

    313b

    Joined:
    Jul 23, 2014
    Posts:
    4
    So I just finished the old version of the roll-a-ball tut a couple weeks ago. Your sample projects are great learning resources, by the way. Is the code for the new version (and your other tutorials) available anywhere outside of the videos so I can compare or do I need to watch the new videos again?

    thanks
     
    brian-wanamaker likes this.
  4. Julio Gibran

    Julio Gibran

    Joined:
    Apr 17, 2015
    Posts:
    1
    HI, i have a problem when i use de play mode to see the results of the script the ball just dont move. I've press all the keys buy it doesn't move. Do you imagine what my mistake would be? I check the script and re-write it twice alredy but nothing change at all.
     
  5. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Normally, the code is available on the "Page" the video is embedded in. I have not yet added the new code for "Roll-a-Ball in Unity 5" yet. I will next week.
     
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    There are two parts to making things work. The scripting side, and the editor side. Often this is an issue of not setting the speed value in the inspector. Double check all steps, not just the code steps, but the steps taken in the editor.
     
    CalenLoki likes this.
  7. xboxluis4567

    xboxluis4567

    Joined:
    Apr 20, 2015
    Posts:
    1
    i have a tiny bity question on the "roll a ball" am trying to move the ball but its not working. why not?
     
  8. luxaorta

    luxaorta

    Joined:
    Apr 4, 2015
    Posts:
    6
    Thank you very much for updating this!

    I was going crazy trying to figure out what to do since I am a total noob. :)
     
  9. Pequisto

    Pequisto

    Joined:
    Apr 21, 2015
    Posts:
    66
    Thank you for this!
     
  10. luxaorta

    luxaorta

    Joined:
    Apr 4, 2015
    Posts:
    6
    Just a minor issue. When I create the player and spin around the play area, he is really slow. Almost as if the weight is that of boulder as opposed to a marble in the videos.

    Any thing I can change in the set up fix it?
     
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you give us any additional information? Do you have any errors in the console? This could be many issues depending upon what step you are stuck on. In general, simply re-watch the last lesson or lessons from the last time it worked correctly, and pay attention to all the small detail, including values added in the inspector and spelling / capitalisation of items in the scripts.
     
  12. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You're welcome! Our pleasure!
     
  13. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you give us any additional information? Do you have any errors in the console? This could be many issues depending upon what step you are stuck on. In general, simply re-watch the last lesson or lessons from the last time it worked correctly, and pay attention to all the small detail, including values added in the inspector and spelling / capitalisation of items in the scripts.

    If you've checked your scripts and they are correct, it could be a step in the editor... Did you have a speed value?
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Have you arrived at the step where a value for speed is created and you can vary the speed of the ball using this property in the inspector?
     
  15. sidali.tafer

    sidali.tafer

    Joined:
    Jan 18, 2015
    Posts:
    1
    please please please please where is the touch keybord to moving the Player(Sphere)?????????!!!!!!!!!!!!!!!!!!
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I don't understand the question. Can you be a little more clear? I'm not sure what you mean by "touch keyboard".
     
  17. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    Isn't he asking which keyboard key are used to move the player ? In which case, it's the directionnal key of your keyboard.
     
  18. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I'm not sure if this is regarding touch input, which is not covered within the scope of the lesson... Or the keys, which are the arrow keys or ASDW, and should be covered clearly in the be documentation.
     
  19. luxaorta

    luxaorta

    Joined:
    Apr 4, 2015
    Posts:
    6
    Yes, I have the public float variable and it shows in the inspector.

    I've tried changing the speed in the inspector(1-100) and there is no change in the movement speed of the ball.
     
  20. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
  21. luxaorta

    luxaorta

    Joined:
    Apr 4, 2015
    Posts:
    6
    Here's the code:


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class playerControl : MonoBehaviour {
    6.  
    7.     public float speed;
    8.     public Text countText;
    9.     public Text winText;
    10.  
    11.     private Rigidbody rb;
    12.     private int count;
    13.  
    14.     void Start ()
    15.     {
    16.         rb = GetComponent<Rigidbody> ();
    17.         count = 0;
    18.         SetCountText ();
    19.         winText.text = "";
    20.     }
    21.     void FixedUpdate ()
    22.     {
    23.  
    24.         float moveHorizontal = Input.GetAxis ("Horizontal");
    25.         float moveVertical = Input.GetAxis ("Vertical");
    26.      
    27.             Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    28.  
    29.             rb.AddForce (movement);
    30.     }
    31.     // Destroy everything that enters the trigger
    32.  
    33.     void OnTriggerEnter (Collider other)
    34.     {
    35.         if (other.gameObject.CompareTag ("pickup"))
    36.         {
    37.             other.gameObject.SetActive (false);
    38.             count = count +1;
    39.             SetCountText();
    40.         }
    41.     }
    42.     void SetCountText()
    43.     {
    44.         countText.text = "Count: " + count.ToString ();
    45.         if (count >= 13) {
    46.             winText.text = "You Win!";
    47.         }
    48.     }
    49. }
    50.  
     
  22. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    You have a speed variable but you never use it to modify your ball movement.
     
  23. luxaorta

    luxaorta

    Joined:
    Apr 4, 2015
    Posts:
    6

    EDIT I found it the issue. I didn't have (movement * speed) set up. Just (movement).



    Thanks again! <solved> :)
     
  24. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Yay!
     
  25. jylehr

    jylehr

    Joined:
    Apr 21, 2015
    Posts:
    5
    So, i've been at the part 3 of the tutorial for the past hour. I can not seem to get the ball to move....
    here is the ode i have so far:
    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody rb;

    void Start ()
    {
    rb = GetComponent<Rigidbody>();
    }

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

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

    rb.AddForce (movement * speed);
    }
    }


    and here is the error that keeps popping up :(
    NullReferenceException: Object reference not set to an instance of an object
    PlayerController.FixedUpdate () (at Assets/scripts/PlayerController.cs:20)

    i've tried just about everything, i'm using unity 5.0.1f1 personal
    pls help....
     
    anees5588 and majorwitty like this.
  26. jylehr

    jylehr

    Joined:
    Apr 21, 2015
    Posts:
    5
    so I realized that the default speed was set to 0, this may have been the reason for my problems, because it is working just fine now.
     
    juandpalacio likes this.
  27. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please learn to format your code using code tags.

    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
    brian-wanamaker likes this.
  28. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Are you still getting this error:
    If so, you may not have a Rigidbody attached.

    You did say that it was working, so it looks like you've figured it out.
     
  29. Arcanox

    Arcanox

    Joined:
    Apr 23, 2015
    Posts:
    3
    Hola, escribí todos los códigos que me pidieron, pero no logro hacer que la esfera se mueva, no me aparece error alguno.:(.
    Ayuda.
    I speak spanish
     
    Giaso likes this.
  30. Arcanox

    Arcanox

    Joined:
    Apr 23, 2015
    Posts:
    3
    upload_2015-4-23_9-22-39.png
     
    Zainul likes this.
  31. Arcanox

    Arcanox

    Joined:
    Apr 23, 2015
    Posts:
    3
    I did do it :)
     
  32. andycastaneda

    andycastaneda

    Joined:
    Apr 23, 2015
    Posts:
    2
    I start getting errors once I try to add text in lesson 8. The counter is working correctly otherwise.
    The referenced script on this Behaviour is missing!
    GameObject (named 'EventSystem') references runtime script in scene file. Fixing!
     
  33. andycastaneda

    andycastaneda

    Joined:
    Apr 23, 2015
    Posts:
    2
    Well it seems the errors came from a built-in script being corrupted somehow...? Anyway I just started over and I worked this time.
     
  34. Shadston

    Shadston

    Joined:
    Apr 24, 2015
    Posts:
    13
    Hey guys, I wanted to improve this game a little bit, so I wrote a script which spawns pickUp elements in random places of playground, after that I wanted to create script which spawns holes in random places in the ground, which our player can fall through but I dont have any idea how to remove collider in certain point of the ground. Could you give me some advice? Or any link to tutorial? I've tried to find something on my own, but still don't have anything.

    PS. For now I am using something like this:

    void OnTriggerStay(Collider myCollision)
    {
    if (myCollision.gameObject.name == "Player") {
    myCollision.enabled = false;
    }
    }

    But I don't think that this is the most professional way.

     
    Last edited: Apr 24, 2015
  35. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    I don't think you can make holes in the collider. What you can do is make different ground with holes n differents places and swap grounds to make holes "appears". But I think it's gonna causes some issues because you will lose you mesh, your ridig body and your collider for a frame. And I don't think thats good.
     
  36. Desoxi

    Desoxi

    Joined:
    Apr 12, 2015
    Posts:
    195
    Hey^^

    Im not a pro because im still working through the tutorials, but i guess you could disable the SphereCollider and after a short delay reenable it. For the wholes you could use Invoke and instantiate something like a black round circle on the floor which looks like a hole. But i dont know how you can make that you can "see through" this wholes and the floor beneath in that spot where you spawned the circle... :/
    With this the player just would fall through the circle, which would like rly unrealistic^^
     
  37. Zamas

    Zamas

    Joined:
    Apr 15, 2015
    Posts:
    35
    MAybe if it's possible to change a material ingame in one frame. For that you would need a dedicated texture. Something with a black circle. Then trigger a materiel change.
     
  38. Desoxi

    Desoxi

    Joined:
    Apr 12, 2015
    Posts:
    195
    Yes but if you rly want the "holes" to appear randomly, you cant just switch to another texture with a hole where you want it to be^^
    I googled a bit and it seems to be difficult to generate realtime holes in meshes without knowledge of shaders etc. :/
     
  39. Shadston

    Shadston

    Joined:
    Apr 24, 2015
    Posts:
    13
    You are right guys, it doesn't seem to be easy task xD I am gonna stick to my idea, maby it looks a little bit unrealistic, but works for now. There are more basic things that I have to learn first :p
     
  40. Desoxi

    Desoxi

    Joined:
    Apr 12, 2015
    Posts:
    195
    Can anyone tell me why "rb.AddForce(Vector3.zero);" still moves the ball?
    It gets velocity over time (i guess something like epsilon), but if you wait long enough the ball starts moving veeeery slow and builds up in speed.
    If i remove the rb.AddForce() line, it stays at velocity = 0.
     
  41. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Sadly. I'm seeing something like this as wel ll and I don't know why. Can to submit a bug using the in-editor but reporter (under the help menu) and then get me the bug number?
     
    Last edited: Apr 27, 2015
  42. Zainul

    Zainul

    Joined:
    Apr 25, 2015
    Posts:
    1
    wrote the script 5 times still not working here is my script still in tutorial 2 for movement
    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    private Rigidbody rb;

    void start ()
    {
    rb = GetComponent<Rigidbody> ();
    }

    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVerticle = Input.GetAxis ("Verticle");

    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVerticle);

    rb.AddForce (movemet);
    }
    }
     
  43. Kaziarl

    Kaziarl

    Joined:
    Apr 23, 2015
    Posts:
    10
    If this is copied directly from your code, then this is likely the problem here. "Start" needs to be capitalized.

    Also, at this step when I did it the ball moved almost imperceptibly slow until I added "speed" to the rb.AddForce line. Which is the next step after where it looks like you are, as I recall.
     
    relykx likes this.
  44. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please learn to format your code:
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  45. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @Kaziarl is correct on both accounts! Thanks Kaziarl!
     
  46. Desoxi

    Desoxi

    Joined:
    Apr 12, 2015
    Posts:
    195
    Hey, i submitted the bug, but what exactly do you mean with the big number..? :D

    EDIT: If you mean the case number, here it is: 692584
     
  47. Silversmygare

    Silversmygare

    Joined:
    Apr 26, 2015
    Posts:
    2
    Hello!
    I'm having so much trouble with the Canvas, Count Text and EventSystem. I've followed the instructions exactly (I think) but I end up with a lot of errors and warnings after I've added the counter stuff in the script and then referenced the Count Text to the Player.

    The warnings I get are of the type : "The referenced script on this behaviour is missing". (and they highlight the canvas or the eventsystem when I click on them!"

    And also errors for the three different things "GameObject (named 'Count Text') references runtime script in scene file. Fixing!".

    Also one of this kind: "NullReferenceException: Object reference not set to an instance of an object
    PlayerController.Start () (at Assets/Script/PlayerController.cs:20)" ....

    Maybe it has nothing to do with it, but when I create a new text field and a canvas gets created alongside, the canvas is not aligned to the origin! So i have to reset the position of the text field to start with to see it....

    Help! :D
     
  48. ua_ACCACIH

    ua_ACCACIH

    Joined:
    Apr 25, 2015
    Posts:
    5
    Good day!
    Sorry for my English. The ball moves after only 10 seconds :mad:. This is the correct behavior?
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour {
    6.  
    7.     public float speed = 100.0f;
    8.  
    9.     private Rigidbody rb;
    10.  
    11.     void Start ()
    12.     {
    13.         rb = GetComponent<Rigidbody>();
    14.     }
    15.  
    16.     void FixedUpdate ()
    17.     {
    18.         float moveHorizontal = Input.GetAxis ("Horizontal");
    19.         float moveVertical = Input.GetAxis ("Vertical");
    20.  
    21.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    22.  
    23.         rb.AddForce (movement * speed);
    24.     }
    25. }
     
    isra2002 likes this.
  49. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Thanks! Escalating.
     
    nelka nirmal likes this.
  50. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Not sure about the last bit: The canvas not aligned to origin. If you can recreated this 100%, can you file a bug report with the in-editor bug-reporter and give me the report number, so I can look more closely?

    -

    Now, the other issues:
    "The referenced script on this behaviour is missing" means just that: A script is missing. Having scripts missing from the EventSystem and Canvas, unless you put a script on there and removed it, is a bad thing. You'd need to replace the missing script.

    I have never seen anything like: "GameObject (named 'Count Text') references runtime script in scene file. Fixing!" before... Scary!

    "NullReferenceException: Object reference not set to an instance of an object PlayerController.Start () (at Assets/Script/PlayerController.cs:20)" is a run-of-the-mill Null Ref Error. This means you are trying to access something by a reference, and that thing is not linked or referenced correctly. This is usually because a public reference is not properly connected in the inspector. The rest of the error says that you need to look at the script "Player Controller" in the "Start()" function which can be found at "Assets/Script/PlayerController.cs" at line 20. Look at line 20 to see what's messed up.

    -

    To fix these:
    I would back up to the point where you started making the UI, delete everything you've done up to that point (or return to a saved backup) and carefully repeat the steps. Something's gotten way messed up and it may be easier to start again than to try and figure out what it is.
     
    nelka nirmal and Silversmygare like this.