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. marroon69

    marroon69

    Joined:
    Jan 13, 2017
    Posts:
    3
    Hmmm So I deleted and restarted the project and the main Camera and Directional Light are there now....not sure what I did wrong.
     
  2. ReinoldJudd

    ReinoldJudd

    Joined:
    Jan 11, 2017
    Posts:
    7
    I had exactly the same issue and fix
     
  3. ReinoldJudd

    ReinoldJudd

    Joined:
    Jan 11, 2017
    Posts:
    7
    So I have... not an issue, exactly, but a question. In the tutorial, he sees all his files at once, broken down by folders and files. I only see within the folder I have open. How can I change my view so I can see all the files at once?
     
  4. Niblo

    Niblo

    Joined:
    Jan 13, 2017
    Posts:
    7
    Hi Unitiers,

    I am a brand new member of the programming community and have never coded before, so forgive me if the question seems trivial.

    I am up to part 6 in the Roll a Ball tutorial and for some reason, my CameraController script is no longer working with my player gameobject. In fact, when I hit play, the player gameobject completely disappears.

    The problem goes away, when I remove the player variable from the controller inspector, but then the camera no longer follows my player game object.

    Thanks :)
     
  5. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Apologies, Im not 100% sure what you have in your project, would it be possible to add a screenshot so we can see?

    It may be that you have accidentally changed your layout, or changed how the project window looks from a single column, or two column view. (for info on the project view have a look here Link to Manual Page) but a screenshow will definetly help.
     
  6. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    No such thing, asking questions is how we all learn :)

    when you say disappeared, is the player object still listed in the scene heirarchy, or is it not visible within the game window when you test?

    could you paste the code for your CameraController script please so we can have a look? if you could, when posting your code use the code tags button, just makes reading alot easier as its formatted and numbered.
    info link for code tags

    at first guess, it does sound like the offset between player and ball could be incorrect.
    within your CameraController script, does your Start() method have a capital S? as this is where the offset distance is calculated, and if it is start() instead of Start() then it will not get called and your camera will end up at exactly the same place as the player, and wont get the proper view.
     
  7. Niblo

    Niblo

    Joined:
    Jan 13, 2017
    Posts:
    7
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraController : MonoBehaviour {
    6.  
    7.     public GameObject player;
    8.  
    9.     private Vector3 offset;
    10.  
    11.     void Start (){
    12.         offset = transform.position - player.transform.position;
    13.         }
    14.  
    15.     void LateUpdate (){
    16.         player.transform.position = player.transform.position + offset;
    17.         }
    18.  
    19.  
    20.  
    21. }
    Howdy! Thanks for getting back to me!

    Yeah I checked and the S is capital. The problem seemed to occur when I dragged the player game object into the main camera object holder i made in the CameraController script.

    The player gameobject is still there in the heirachy, it doesn't disappear, it's the actual physical sphere. It's there before I attach the player game object to the camera controller script, then when I hit play it's gone. However when I remove it, the camera stops and the ball resumes it's normal movement. It's strange.

    Cheers!
     

    Attached Files:

    Last edited: Jan 14, 2017
  8. Lujach

    Lujach

    Joined:
    Jan 15, 2017
    Posts:
    2
    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. }
    I just finished part 2 of the roll a ball tutorials and i can't seem to get my ball to roll. I have copied the code from the video but still can't find the issue. I've also tried setting the speed all the way from 1-100 but that still didn't resolve this issue.

    Thanks!
     
  9. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Check out line 15 in your code. It should be FixedUpdate. Capitalize the U.
     
  10. Lujach

    Lujach

    Joined:
    Jan 15, 2017
    Posts:
    2
    Thank you that really helped me out
     
  11. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Im not at pc just now as im at work.
    But in your LateUpdate () you are setting the players transform as opposed to the cameras transform.

    Try
    Code (CSharp):
    1.  
    2. void LateUpdate (){
    3.         transform.position = player.transform.position + offset;
    4.         }
    5.  
     
  12. Niblo

    Niblo

    Joined:
    Jan 13, 2017
    Posts:
    7
    Thank you so much! Worked a treat! Legend! Now I can finish this! Thanks again!
     
  13. ReinoldJudd

    ReinoldJudd

    Joined:
    Jan 11, 2017
    Posts:
    7
    So my project always looks like this:

    project.png

    The tutorial has one that looks like this:
    tutorial.png

    How can I make my window look like that?
     
  14. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Upper right corner of your project window is the menu. Change between one column or two column layout, if I understand what you are asking correctly.
     
    OboShape likes this.
  15. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    did you try a One column layout? should be it.
     
  16. VoidArcade

    VoidArcade

    Joined:
    Jan 17, 2017
    Posts:
    1
    I have a question... it says "The referenced script on this Behaviour (Game Object 'Player') is missing!" and i dont know how to fix
     
  17. Sir_Rush

    Sir_Rush

    Joined:
    Jan 17, 2017
    Posts:
    2
    So I keep getting the error "Argument Exception: Input Axis Horizontal is not setup" and I've checked my input manager and I don't know whats wrong. This is my input manager:
    Capture.PNG
     
  18. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have a look at the script with the issue on the Player. Double check that the script filename matches the class name exactly, then you can remove and readd the script to see if that works.

    So for example if the filename is 'PlayerController.cs' then the script must have the class name of 'PlayerController' same spelling and case sensitivity.
     
  19. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    In the script have u spelled 'Horizontal' correctly when using the GetAxis?. Just wondering

    If you comment out the line for that bit. Does the Vertical axis work?
     
  20. Sir_Rush

    Sir_Rush

    Joined:
    Jan 17, 2017
    Posts:
    2
    Thank you that was the problem it's now working, I had spelled it "Horizonal".
     
    OboShape likes this.
  21. DBDBDDBDBD

    DBDBDDBDBD

    Joined:
    Jan 18, 2017
    Posts:
    10
    Hi , i have a problem on me ,
    i watch Roll a Ball game - 2 of 8: Moving the Player ,
    and everything is ok ,
    when i press A and D ,
    it's didn't move,
    only W and S can move

    and i check my code , i can't find the problem

    plz help me , this is my code


    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.        
    13.         rb = GetComponent<Rigidbody> ();
    14.        
    15.     }
    16.    
    17.    
    18.    
    19.    
    20.     void FixedUpdate ()
    21.     {
    22.         float moveHorizontal = Input.GetAxis("Horizontal");
    23.         float moveVertical = Input.GetAxis("Vertical");
    24.        
    25.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    26.        
    27.         rb.AddForce (movement * speed );
    28.     }
    29.    
    30. }
    31.  
     
  22. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    MoJaJa,

    Code looks good from what I can tell. Did you try using the arrow keys or check out you Input Manager to make sure there isn't something set up wrong there?

    Go to Edit>Preferences>Input then un the inspector look up Axis>Horizontal.
     
    DBDBDDBDBD likes this.
  23. DBDBDDBDBD

    DBDBDDBDBD

    Joined:
    Jan 18, 2017
    Posts:
    10
    oh i'm dub ,

    i forget to reset the Input Manager ,

    thank you for your help
     
  24. Crispp

    Crispp

    Joined:
    Oct 24, 2016
    Posts:
    1
    This tutorial is the first one i have finished and it works great!

    Thank you Sir, for making this tutorial.
    I understand more of the Unity 3D features now. Looking forward to finish another tutorial!
     
  25. thor1911

    thor1911

    Joined:
    Jan 24, 2017
    Posts:
    2
    Help! :D
    - Moving the Camera Tut

    I can not link my player GameObject to my script? The tutorial says drag and drop but mine is not able, below is my code and a gif to should exactly what I am doing
    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class CameraController : MonoBehaviour {
    7.     public GameObject player;
    8.     private Vector3 offset;
    9.     // Use this for initialization
    10.     void Start () {
    11.         offset = transform.position - player.transform.position;
    12.  
    13.     }
    14.  
    15.     void LateUpdate () {
    16.         transform.position = player.transform.position + offset;
    17.  
    18.     }
    19. }
    20.  

    When I click the o to the right of it, it brings us an Assets dialog box ->

    and its empty?

    What step did I miss?
     
    Last edited: Jan 24, 2017
  26. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    it looks like you have the cameraController script highlighted, as opposed to the camera in the scene that has that script attached, and trying to drag the player to that.

    what you have to do is highlight the Camera that is in the scene, and if you look down in the inspector, your cameraController script will be attached there.

    so with the camera in the scene highlighted, drag the player from the heirarchy into that slot in the inspector.
     
    thor1911 likes this.
  27. thor1911

    thor1911

    Joined:
    Jan 24, 2017
    Posts:
    2
    YOUR THE MAN! :D
    I looked around and fixed it with
    Code (csharp):
    1.  
    2.     void Start () {
    3.         player = GameObject.FindWithTag("Player");
    4.         offset = transform.position - player.transform.position;
    5.     }
    6.  
    but I wanted it to the T of what the tutorial was teaching, thank you so much buddy. I just downloaded unity 3d this morning and am having a go at this! :)
     
  28. quiden

    quiden

    Joined:
    Jan 26, 2017
    Posts:
    1
    Hello, I am new to Unity and have a programming class that I'm developing a plan for learning Unity for. I'll be doing the Roll A Ball tutorial as part of it and I'm curious how much time I should expect to take. I need to submit a plan for weekly progress and things to show. I see the tutorial is broken down into three main parts with subsections. Would you suggest a part per week? Maybe two parts per week? or are the subsections complex enough to be part of the equation? or is it straight forward enough to do in one week in entirety? Thanks!
     
  29. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Really going to be up to you to decide depending on available class time and student level.

    The videos themselves range in length between around 5 minutes up to close to 20 minutes. I would say the average is around 13 - 14 minutes. They are pretty compact, not a lot of wandering around or wasted time. You may want to just preview each to get the running length, make a chart and use that for a guide post.

    Typically, as a complete beginner, I would allow myself a minimum of twice the video length to watch, do the work and take notes.

    Hope that helps.
     
  30. Deleted User

    Deleted User

    Guest

    Make it thrice. ;)
     
  31. chaeyoungAngie

    chaeyoungAngie

    Joined:
    Jan 27, 2017
    Posts:
    1
    Hello,

    I just start to use unity and trying to follow the tutorial.
    But for some reason, my ball moves down z axis rather than horizontal.
    My c# script is exactly same as the tutorial.
     
  32. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Please post you Player_Controller script so we can look at it.
     
  33. Kazujobs

    Kazujobs

    Joined:
    Jan 30, 2017
    Posts:
    2
    How can I change the colour of the ground?
    I watched video, but I could not find the "background" on my screen.
     
  34. Kazujobs

    Kazujobs

    Joined:
    Jan 30, 2017
    Posts:
    2
    Screen Shot 2017-01-30 at 12.55.44 AM.png
     

    Attached Files:

  35. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Kazujobs,

    Make sure the ground is selected. In the inspector go to the default material / shader component. See the box marked Albedo ( the rectangular box with the eye dropper next to it ). Click on the box and a color picker window should pop up.
    Select the color you want and close the window.
     
  36. Speedfiets

    Speedfiets

    Joined:
    Jan 31, 2017
    Posts:
    4
    Hey guys,

    I'm new at this so I started with the tutorial: Roll-a-ball. I'm now at section 3.02.
    I made the script to trigger the pick ups. I can roll the ball (player) put I cant pick up the cubes.
    The ball just rolls through to the cubes and they don't disappear.
    I got the tag for the cubes copied from the script so I know for sure that the tag is good. I hope you can help me.

    Code (CSharp):
    1. public class PlayerControler : MonoBehaviour {
    2.  
    3.     public float speed;
    4.  
    5.     private Rigidbody rb;
    6.  
    7.     void Start ()
    8.     {
    9.         rb = GetComponent<Rigidbody>();
    10.     }
    11.  
    12.     void FixedUpdate ()
    13.     {
    14.         float moveHorizontal = Input.GetAxis ("Horizontal");
    15.         float moveVertical = Input.GetAxis ("Vertical");
    16.  
    17.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    18.  
    19.         rb.AddForce (movement * speed);
    20.     }
    21.  
    22.     public class ExampleClass : MonoBehaviour
    23.     {
    24.         void OnTriggerEnter(Collider other)
    25.         {
    26.             if (other.gameObject.CompareTag("Pick Up"))
    27.                 other.gameObject.SetActive(false);
    28.         }
    29.     }
    30. }
     
  37. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Why do you have your OnTriggerEnter method inside of another class? I don't seem to recall that in the tutorial. Try eliminating lines 22,23 & 29. This will put your OnTriggerEnter method back into your player controller class.

    And of course the usual suspects, make sure your Tag name and CompareTag name are exactly the same and make sure your pick ups are "tagged" and that they are set up as triggers.

    edit: Also you will be adding more lines to your If(gameObject.CompareTag) so you may want to put your curly braces in.
     
    Speedfiets likes this.
  38. Deleted User

    Deleted User

    Guest

    @Ryeath is right

    Code (CSharp):
    1.     public class ExampleClass : MonoBehaviour
    2.     {
    3.           ...
    4.     }
    has nothing to do here. Place

    Code (CSharp):
    1.         void OnTriggerEnter(Collider other)
    2.         {
    3.             if (other.gameObject.CompareTag("Pick Up"))
    4.             {
    5.                 other.gameObject.SetActive(false);
    6.             }
    7.         }
    after void FixedUpdate (); (make sure you don't place it inside void FixedUpdate ()) and things should be good.

    You must be extra careful when you write a script, check it several times in a row for typos, syntax errors, oversights, etc. and never use copy and paste. ;)
     
    Speedfiets likes this.
  39. yongjing

    yongjing

    Joined:
    Feb 1, 2017
    Posts:
    2
    Edit: i found my spelling mistake
    hi im doing the "moving the camera" part of this tutorial and i get a compile error after saving the script:

    Assets/Scripts/CameraController1.cs(20,41): error CS1061: Type `UnityEngine.Transform' does not contain a definition for `postion' and no extension method `postion' of type `UnityEngine.Transform' could be found. Are you missing an assembly reference?

    This is my script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraController : MonoBehaviour {
    6.  
    7.     public GameObject player;
    8.     private Vector3 offset;
    9.  
    10.     // Use this for initialization
    11.     void Start ()
    12.     {
    13.         offset = transform.position - player.transform.position;
    14.     }
    15.  
    16.     // Update is called once per frame
    17.     void LateUpdate ()
    18.     {
    19.         transform.position = player.transform.postion + offset;
    20.     }
    21. }
    22.  
    Thanks!
     
    Last edited: Feb 1, 2017
  40. Deleted User

    Deleted User

    Guest

  41. yongjing

    yongjing

    Joined:
    Feb 1, 2017
    Posts:
    2
  42. Speedfiets

    Speedfiets

    Joined:
    Jan 31, 2017
    Posts:
    4
    thanks a lot for the help. deleting the lines directly helpt to solve the problem and works goed now.
     
  43. alexjr1194

    alexjr1194

    Joined:
    Feb 3, 2017
    Posts:
    4
    i have been having trouble getting the ball to move after i out in the first part of the code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour {

    private Rigidbody rb;

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

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

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

    rb.AddForce (movement);
    }
    }
    this is the code i have so far but for some reason i can't get the ball to move this is my first time working with unity so idk what i did wrong
     
  44. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    alexjr1194,

    In scripting you need to pay very close attention to detail when typing stuff in. I see a couple typos.

    void Start () - Start should be capitalized
    void FixedUpdate () - not FixedUpdated no d at the end

    Fix those and try again.
     
  45. alexjr1194

    alexjr1194

    Joined:
    Feb 3, 2017
    Posts:
    4
    thanks i made those fixes and it works now
     
  46. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
  47. s1mpleduck

    s1mpleduck

    Joined:
    Feb 4, 2017
    Posts:
    6
    Whenever I hit play my pick up blocks disappear. Help me plz
     
  48. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    s1mpleduck,

    Could you post your controller script.
     
  49. s1mpleduck

    s1mpleduck

    Joined:
    Feb 4, 2017
    Posts:
    6
    using UnityEngine;
    using System.Collections;

    public class playercontrol : 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);
    }

    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.CompareTag("Pick Up"))
    {
    other.gameObject.SetActive(false);
    }
    }
    }
     
  50. Deleted User

    Deleted User

    Guest

    Use code tags !

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