Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official Roll-a-ball Tutorial Q&A

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

  1. lev180

    lev180

    Joined:
    Jul 12, 2016
    Posts:
    1
    Hello I am having the same problem, I was able to hook it up to the space key (and by extension any key on the key board) but was unable to connect it to the mouse. I tried trading out the input lines with something similar to the input on the example below but still failed to work. I'm stuck. docs.unity3d.com/ScriptReference/Input.GetAxis.html
     
  2. xuanquang1999

    xuanquang1999

    Joined:
    Jul 12, 2016
    Posts:
    4
    I've followed this tutorial and everything works well until the game building part.
    In unity, everything work flawlessly.
    But when I build the game and run it, all I see is the grey color of the ground and the "Point" text.
    What could have been wrong?
     

    Attached Files:

  3. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Are you still getting issues where the ball doesnt move with the arrow keys?
    Why are you using the mouse, just that this is based on keyboard movement of the arrow keys?
     
  4. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    when you play the game, pause it, return to the scene window and check where the camera is, I would suggest that the camera has not been positioned correctly as all you are seeing is the background. the text will display ok as in this case its in GUI screenspace and not based on what the camera is seeing or pointed towards.
     
  5. alnasri1

    alnasri1

    Joined:
    Jul 14, 2016
    Posts:
    1
    The player is not moving i saw the vedio and i did the same thing
    upload_2016-7-14_10-40-48.png
    using UnityEngine;
    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);
    }
    }
     
  6. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836

    If you look in your inspector right at the bottom, you have the script 'NewBehaviourScript'. and this script could not be loaded.

    Looks like you have forgot to name the script.

    The script name must be the exact same as the class name at the top of the script.

    so where you have
    Code (CSharp):
    1. public class PlayerController : MonoBehaviour
    in your script, the script filename must be PlayerController.cs

    rename the file. remove and readd the script to the player gameobject, see how you get on.
     
  7. xuanquang1999

    xuanquang1999

    Joined:
    Jul 12, 2016
    Posts:
    4
    upload_2016-7-15_10-38-28.png

    Here's the screenshot of the camera object. I don't see anything wrong with it.
     
  8. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Ah, apologies , didnt read it correctly, my brain read play mode, instead of build :(

    do you just have the one scene? just wondering in case theres an old scene in your build project.

    if you go to File --> Build Settings, remove the scene thats in the list, then, Add current scene and try building again.
     
  9. xuanquang1999

    xuanquang1999

    Joined:
    Jul 12, 2016
    Posts:
    4
    There's just one scene in the project. And the game is actually working, the only problem is that all of the graphics are missing (except text UI).
     
  10. mukammil

    mukammil

    Joined:
    Jul 17, 2016
    Posts:
    1
    thumb_IMG_1736_1024 2.jpg How can I roll the ball in mobile (iOS device). when I installed the generated build its showing the game but unable to move the ball with touch.. Do I need to do anything (extra coding to take input from touch) for this to work in iOS apart from what is there in the tutorial ?
     
  11. anees5588

    anees5588

    Joined:
    Jul 17, 2016
    Posts:
    3
    Pls help me how to get rid of NullReferenceException
    My code is this below:
    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 moveVertical = Input.GetAxis ("Vertical");

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

    rb.AddForce (movement); (the error comes here)

    }
    }
     
  12. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    you will need to change
    Code (CSharp):
    1. void start ()
    to be
    Code (CSharp):
    1. void Start ()
    Be mindful that C# is case sensitive.

    if you watch the console output window, and if you click on the error it gives you it will show you a little more info on what is happening to give some direction where to look. more than likely it will show you the line where you go to AddForce, then you can trace back from there.
     
    anees5588 likes this.
  13. anees5588

    anees5588

    Joined:
    Jul 17, 2016
    Posts:
    3
    Hey thankx for that i fixed it thankx very much
     
    Last edited: Jul 18, 2016
  14. SeanCott15

    SeanCott15

    Joined:
    Jul 21, 2016
    Posts:
    1
    I have followed the script exactly, made sure that void Start was capitalized, I changed the speed to 10, but when I hit ctrl + play can't move the ball. what am I doing wrong?
     
  15. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Are you sure the ground is the right size?
     
  16. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    You need to use the wsad keys to move the ball, not just click "play".
     
  17. zupicucko

    zupicucko

    Joined:
    Jul 21, 2016
    Posts:
    1
    Why do I have the white line on the middle? How can I remove it?
     

    Attached Files:

  18. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    You don't remove it; it's the GUI, where the texts display in game mode.
     
  19. piranha4D

    piranha4D

    Joined:
    Jul 20, 2016
    Posts:
    2
    I left this as a comment on the last Youtube video, but it occurred to me that the relevant people might not see it, so I am copying it here:

    This was seriously the best tutorial series I have seen in a long time. Most people waste my time with not planning their lessons much, making unplanned errors and backtracking, with a lot of hemming and hawing. But this was meticulously scripted and narrated. Now, I'm a professional programmer (albeit not familiar with C# yet), so I don't know how easy this would be to understand for somebody who knows nothing about coding and has never seen an IDE, but for me this was well-paced. I'm now busy modifying my RollaBall game to respond to acceleromator input, and for my player to get fatter as he gobbles up cuboids, which bounce around more vigorously. ;)

    This is how learning should be -- instructive and at the same time fun. Your tutorial development team is aces. Thank you very much for this resource.
     
    OboShape and ladyonthemoon like this.
  20. CuriousCooper

    CuriousCooper

    Joined:
    Jul 22, 2016
    Posts:
    2
    Hey everyone!

    I am stuck on getting my ball to pick up (or deactive) the blocks, but instead, the ball disappears, and the x,y,z values keep rolling on up, as if the ball is now invisible and rolling. Attached here is my script and a screenshot with my pick up objects selected. I can't seem to figure out why the ball wishes to disappear.

    I am new to actually posting in forums, so if elaboration is needed, I will be as specific as possible. :D

    I do want to say I'm loving these tutorials! I've learned bits and pieces of Java, Unreal, Python, etc. using tutorials like this, and I know it can be hard to compose these tutorials, but y'all did a fantastic job!

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerControl : MonoBehaviour {
    5.  
    6.     public float speed;
    7.     private Rigidbody rb;
    8.  
    9.     void Start()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12.     }
    13.  
    14.     void FixedUpdate()
    15.     {
    16.         float moveHorizontal = Input.GetAxis ("Horizontal");
    17.         float moveVertical = Input.GetAxis ("Vertical");
    18.  
    19.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    20.         rb.AddForce(movement * speed);
    21.     }
    22.  
    23.     void OnTriggerEnter(Collider other)
    24.     {
    25.        if (other.gameObject.CompareTag ("Pickup") )
    26.             // My boxes are tagged with Pickup as you see above
    27.         {
    28.             gameObject.SetActive(false);
    29.         }
    30.     }
    31. }
    As promised here is a screenshot:

    Unity 5 issue.PNG

    I have the trigger checked for all my boxes; but in short, they make the ball disappear, not the boxes.

    What could I have done wrong?
     
  21. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening, and welcome to the forum :)

    just a minor change needed..

    Ok so looking at your OnTriggerEnter method.

    you've almost answered your own question ;)


    with what you currently have here
    Code (CSharp):
    1. gameObject.SetActive(false);
    you are setting the gameobject that the script is attached to, in this case the player, as inactive.

    what you actually want here, is to set the OTHER gameobject (pickups) to be inactive, so change that line to
    Code (CSharp):
    1. other.gameObject.SetActive (false);
    and that should be you working a treat ;)
     
    CuriousCooper likes this.
  22. CuriousCooper

    CuriousCooper

    Joined:
    Jul 22, 2016
    Posts:
    2
    Oh oh oh, the joys of using an object-oriented programming language. :) I appreciate it so much @OboShape!
     
    OboShape likes this.
  23. Vegeta_

    Vegeta_

    Joined:
    Jul 23, 2016
    Posts:
    4
    First off, A Big thanks to Unity for making a step by step tutorial which showcases the most basics of the Editor. Trust me when I say this, this tutorial has been a BIG help to me. Now I've completed the whole tutorial(Had some errors , Managed to get past them), But I want to go further.

    So what I have in mind is, when the player completes all the pickups, the walls get destroyed. So I managed to do that, the next part was trickier. After destroying the walls I want the score to reset and I want the Ground(Plane) to go up(Like a level up, but in the same Scene). After going up, the walls need to be in place and Ground needs to attach itself exactly below the walls, from where the new pickups generate.

    I'd really appreciate it if anyone could assist me, Doesn't matter if you only give me tutorials related to what I'm saying. Any help is appreciated.

    Peace,
    Vegeta.
     
  24. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    you could look into lerping the position of the floor.

    if you have a position in mind of where to move to ie 10 units up in Y direction, you could lerp from its current position to its target position. and you could do the same with the walls if they are a certain distance above the new position of the floor
    you could lerp them to their new position.

    never tried it, but look around see if these give any inspiration.
    https://unity3d.com/learn/tutorials/topics/scripting/coroutines?playlist=17117
     
  25. Vegeta_

    Vegeta_

    Joined:
    Jul 23, 2016
    Posts:
    4
    Thanks a lot man, that worked quite well. Now that i've dealt with this, I need to make it work only when all pickups of mine have been collected.

    NOTE: The score is in the PlayerController script.

    So the dilemma right now is, How do I use an if statement in my elevator script that checks whether the score is 16?(i.e How to check score count from another script?)

    EDIT: I have a small issue, the plane seems to be moving up, but the Player(Ball) falls off? Any Idea why? Here's the Code.

    Code (csharp):
    1.  
    2. public class Elevator : MonoBehaviour {
    3.  
    4.     public Transform startMarker;    //making a start marker to save start position.
    5.     public Transform endMarker;        //making a end marker to save end position.
    6.  
    7.     private Text text;
    8.  
    9.     public float speed = 1.0F;        
    10.     private float startTime;        
    11.     private float journeyLength;
    12.     void Start() {
    13.         startTime = Time.time;  
    14.         journeyLength = Vector3.Distance(startMarker.position, endMarker.position);      
    15.     }
    16.     void Update() {
    17.         GoUp ();
    18.          
    19.     }
    20.     void GoUp(){
    21.         float distCovered = (Time.time - startTime) * speed;            float fracJourney = distCovered / journeyLength;  
    22.         transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
    23.     }
    24. }
    25.  
     
    Last edited: Jul 24, 2016
  26. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
  27. Vegeta_

    Vegeta_

    Joined:
    Jul 23, 2016
    Posts:
    4
  28. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
    Hello I'm stuck with something I've been trying to work out for ages I'm watching the YouTube series of Unity 5 - Roll a Ball game and I've just finished episode 2/8
    . My problem is that I keep getting a warning and my player is not moving. This is my script and my warning. Can some one please help Thank You.

    using UnityEngine;
    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);
    }
    }
     

    Attached Files:

  29. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Please, post your script using the proper tags.
     
  30. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.  
    6.     public float speed;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     void Start ()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.  
    15.     void FixedUpdate ()
    16.     {
    17.         float moveHorizontal = Input.GetAxis ("Horizontal");
    18.         float moveVertical = Input.GetAxis ("Vertical");
    19.  
    20.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce (movement * speed);
    23.     }
    24. }
     
  31. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
  32. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Your script is correct but it seems that you used different OSes to work on this project. You must correct the line endings in Visual Studio. Open your script in and make sure the line endings are converted to the OS you are currently using (Windows). I have no idea how you can do that in Visual Studio, sorry.

    As for the player not moving, make sure you filled the speed variable in the player inspector, PlayerController.
     
  33. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
    Okay Thank you very much for the help. I'll tell you if it works out.
     
  34. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
    Sorry I dont know what first paragraph means with the OSes and what is good to use instead of visual studios?
     
  35. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Well, my mistake anyway. Just ignore the warnings about the line endings; they won't prevent your script from working.

    So that your player moves, don't forget to set the speed variable in the player's inspector, Player Controller script. :)
     
  36. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
    Alright will do Thank you very much. :)
     
  37. sakula1995

    sakula1995

    Joined:
    Jul 31, 2016
    Posts:
    1
    My player is not picking up the pickups. It was going through the pick ups but the pickups are not diappearing. They still remain same, but my player going through the pick ups after ticking Is Trigger option.
    How can I make my player catch those pickups..

    Please help me...

    Thanks in Advance !!!!!!
     
  38. OneAsterisk

    OneAsterisk

    Joined:
    Aug 2, 2016
    Posts:
    5
    Assets/Scripts/PlayerController.cs(16,13): error CS1525: Unexpected symbol `float'
    Please Help MEEE
     
  39. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Probably double check the pick up tags are set, and they are spelled the same as in your player controller.
     
  40. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Need a bit more to go on. Can you please post your player controller script ( using codes tags). Its more than likely a missed ; or a bracket in the script, and probably within the lines 1 to 16.
     
  41. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
    Hello everyone I have just completed all of "Roll a Ball" MiniGame and everything is working great now thanks for the help @ladyonthemoon I appreciate it. I was wondering what project/thing should I do now or would be good to do? Thank You.
     
  42. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    You're welcome!

    The next project is generally the Space shooter but, did you do those:
    and take a look at those:
    At the same time, I recommend that you do those:
    :)
     
    Last edited: Aug 2, 2016
  43. Urasam

    Urasam

    Joined:
    Aug 2, 2016
    Posts:
    2
    Hello,

    I'm new to Unity and I've just completed the Roll a Ball Tutorial. Everything works fine in Unity but somehow the pick ups don't disappear in the built version. I don't understand why since the game runs perfectly fine in Unity.
    Could anyone help me please?
     
  44. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
    Will do thank you and what is good to use instead of visual studios?
     
  45. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Mono Develop, the built in C# editor does the job. It's a bit buggy but what isn't? ;)
     
  46. JosephWard

    JosephWard

    Joined:
    Jul 29, 2016
    Posts:
    9
    Thank you very much i'll install it now :).
     
  47. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    It's already installed, you just have to choose it in the preferences, external tools (not sure about the name) tab.
     
  48. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    With the Scene open that currently works in the editor.

    Might be worth checking the build settings under File > Build Settings.
    Have a look and see in the top box, there should be one scene in there already, but if you highlight it and delete it.
    then click the 'Add Open Scenes' button, and that should add the current open scene to the build, and then try again to test.
     
    Urasam likes this.
  49. OneAsterisk

    OneAsterisk

    Joined:
    Aug 2, 2016
    Posts:
    5
    I only went from here when in the video he was like ok now lets make sure in unity that nothing is wrong
    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 moveVertical = Input.GetAxis("Vertical")

    Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);

    rb.AddForce(movement);
    }


    }
     
  50. OneAsterisk

    OneAsterisk

    Joined:
    Aug 2, 2016
    Posts:
    5
    Sorry here is a new post with code tags

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.     private Rigidbody rb;
    7.     void Start ()
    8.     {
    9.         rb = GetComponent<Rigidbody>();
    10.     }
    11.  
    12.     void FixedUpdate()
    13.     {
    14.         float moveHorizontal = Input.GetAxis("Horizontal")
    15.  
    16.       float moveVertical = Input.GetAxis("Vertical")
    17.  
    18.          Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
    19.  
    20.             rb.AddForce(movement);
    21.     }
    22.  
    23.  
    24. }