Search Unity

Official Roll-a-ball Tutorial Q&A

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

  1. TDRare

    TDRare

    Joined:
    May 15, 2016
    Posts:
    2
    Solved my problem. Somehow, the "Pick Up" tag i created and added to the Pick Up objects was deleted, so the Pick Up objects were untagged. Why it would work in the editor in this case I'm not sure. I recreated the tag and re-added it to each of my objects and the build now produces a working game.

    I discovered this issue by looking at the output_log.txt file and seeing references to Pick Up not defined at the bottom of the log.
     
    KartikArora111 and OboShape like this.
  2. omardiaa

    omardiaa

    Joined:
    May 15, 2016
    Posts:
    3
    hey guys! wonderful tutorials down there! im completley new to unity (1st project ever) and am stuck in lesson 2-1. i keep getting the error the script associated cannot be loaded, please fix any compilation errors, etc.. when i save the script it tells me something on the lines of gameobject not linked to script(dont remember sorry :D). you answered this question before, by saying you need to link / refrence the gameobject by draging the script to the component (or something like that) but i just couldnt get what you said.. i dont know where to/ what to drag .. here is my code:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CameraController : MonoBehaviour {
    5.  
    6.     public GameObject player;
    7.  
    8.     private Vector3 offset;
    9.  
    10.     void Start ()
    11.     {
    12.         offset = transform.position - player.transform.position;
    13.     }
    14.  
    15.     void LateUpdate ()
    16.     {
    17.         transform.position = player.transform.position + offset;
    18.     }
    19. }
     
  3. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    The code is okay; the script must be attached to the camera. :)

    How to attach scripts to an object is explained in this video: https://unity3d.com/learn/tutorials...cripts-as-behaviour-components?playlist=17117

     
    Last edited: May 17, 2016
    OboShape likes this.
  4. omardiaa

    omardiaa

    Joined:
    May 15, 2016
    Posts:
    3
  5. omardiaa

    omardiaa

    Joined:
    May 15, 2016
    Posts:
    3
    OboShape likes this.
  6. lawmower

    lawmower

    Joined:
    May 20, 2016
    Posts:
    2
    Hello,

    Is there a way to make the ground round?

    Thanks
     
  7. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Last edited: May 20, 2016
  8. Ghost_Tech

    Ghost_Tech

    Joined:
    Oct 20, 2015
    Posts:
    7
    Hi all,

    I have started doing this tutorial (I did it some point last year but got bogged down with real life).

    Anyway I am receiving the following errors when I write the first script to control the ball.

    My Code is as follows:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    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);
    20.     }
    21.  
    22. }
    On another note regarding scripting, I currently have Visual Studio installed. Can anyone advise how I configure Windows or Unity to goto MonoDevelop as opposed to loading Visual Studio?
     
  9. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Coding is case sensitive. You wrote:
    Code (CSharp):
    1. private Rigidbody rb;
    which is right, and then you write:
    Code (CSharp):
    1. rb = GetComponent<RigidBody> ();
    which is wrong.

    To swap from VS to MonoDevelop, open the preferences of the editor and then choose "MonoDevelop" in the "External tools" tab.
     
    OboShape likes this.
  10. lawmower

    lawmower

    Joined:
    May 20, 2016
    Posts:
    2
  11. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    A disc shape, using the primitives at hand. you could create a Cylinder object, GameObject > 3D Object > Cylinder.
    then you can scale the height of the cylinder down in the Y axis to say 0.1, and that would give you a sort of coin/disc shape.

    But, that just gives you a mesh shape, the difficulty would come in providing this shape with a collider which is a whole other box of frogs, whereby you would have to remove its current capsule collider and add a mesh collider which would fit the object and allow for the physics interaction to have the player something to roll on, but down the line when your objects get more fancy this collider may come at a performance expense.
    see tutorial outline on colliders..
    http://unity3d.com/learn/tutorials/modules/beginner/physics/colliders?playlist=17120


    Not sure how else you would get it done :(

    But, for this tutorial series, stick to the primitives as in the lessons and once your completed the series you can always go back and have a tinker and play around to see what else you can do ;)
     
    Last edited: May 22, 2016
    lawmower likes this.
  12. timisenman

    timisenman

    Joined:
    May 22, 2016
    Posts:
    5
    Hi there,

    I just finished my first build, and when I loaded my game, the collisions aren't working. Everything works perfectly in Play mode in the editor, but after the build, the functionality is lost.

    Anyone else experience this, or have any advice?

    Thanks in advance.
     
  13. timisenman

    timisenman

    Joined:
    May 22, 2016
    Posts:
    5
    Same here. Am searching for solutions. Will let you know if I find anything.
     
  14. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Nice one, glad you got it going.

    Good work doing research for a solution ;)
     
  15. timisenman

    timisenman

    Joined:
    May 22, 2016
    Posts:
    5
    I actually haven't yet, but this seems to be my issue as well (from TDRare):
    Solved my problem. Somehow, the "Pick Up" tag i created and added to the Pick Up objects was deleted, so the Pick Up objects were untagged. Why it would work in the editor in this case I'm not sure. I recreated the tag and re-added it to each of my objects and the build now produces a working game.

    Going to try this now.
     
  16. timisenman

    timisenman

    Joined:
    May 22, 2016
    Posts:
    5
    This definitely solved the issue. Also don't know why the tags are breaking :(
     
  17. timisenman

    timisenman

    Joined:
    May 22, 2016
    Posts:
    5
    Inconsistency between the strings in the code and the tags in the editor was the answer. My work here is done.
     
    OboShape likes this.
  18. KartikArora111

    KartikArora111

    Joined:
    May 13, 2016
    Posts:
    2
    HELP!!
    I downloaded unity last week. Started working on the roll a ball project but encountered trouble right from the start. I tried to fix stuff by myself and got the ball to move on the plane today. But i would like to get some answers. Here we go:

    (1) When i created the new 3D project i didn't get any default Directional light and Skybox in the scene.There was a main camera with ortjographic view. I fixed the cam view and added the directional light. How do i get these by default?

    (2)How do i add a skybox to the scene?

    (3)When I started the game the plane and ball started falling under gravity.Why?

    (4)To stop the plane from falling i enabled the "Is Kinetic" check box for the plane. What does "Is kinetic" feature do?

    (5)At some point the ball was falling through the plane so i added a "Mesh Collider" component to the plane. But the collider was much larger than the plane itself. So the ball would not fall even when it was off the plane. Can i size the mesh collider?


    Thanks for reading the whole post. :)
     
  19. VFigueiredo

    VFigueiredo

    Joined:
    May 29, 2016
    Posts:
    1
    I am really stuck on this for a few hours by now:
    After a lot of debug process I get this message The reference script on this Behaviour (Game Object 'Player') is missing!

    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.         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 am with rigidbody component, my speed is set as 10, my gravity is on and my Kinematic off, I attached the player script with the object 'Player', but it simply does not move.

    Thanks for the patience.
     
  20. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Your script is not attached to the player.
     
  21. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon,

    1: Sounds very much like a 2D project created by accident.
    I would possibly close and try recreating a new project, and ensure that the 3D option is highlighted in red when creating.

    2: When creating a new 3D project, the skybox should be there by default, along with a Main Camera and directional light in the heirarchy pane.
    But, when a 2D project is created you dont get the skybox or directional light, only the main camera.

    But for info, the skybox can be accessed from the lighting tab via the editor 'Window > Lighting", within that pane that opens, the 'Scene' button should be clicked at the top, and the skybox is at the top of the list, you should be able to click the little circle select dot to the right and select the Default-Skybox.
    Just as a not as well, a directional light is needed if you would like to get to the same look as the starting scene with the tutorial. if there is no directional light in the scene heirarchy, one can be created via the editor menu 'GameObject > Light > Directional Light'


    3: To have something fall under gravity we need to add the Rigidbody component (covered under the moving player video) this allows physics forces to be applied to an object. We add a Rigidbody to the ball as physics are used to drive it around. but the plane should not have a Rigidbody as this is our static floor.

    4: if the 'is kinematic' option in the Rigidbody component is ticked, as far as im aware, this indicates that forces, collisions etc will not affect the objects rigidbody anymore, it will be under the control of animation and scripts.

    5: there should be a mesh collider attached to the plane by default and this should scale accordingly when you scale the plane. I would delete the plane you have and create a new one with the menu GameObject > 3D Object > Plane (or with the create button in the heirarchy)


    But that said, I would definitely try and recreate a new 3D project to begin with, and follow along adding the objects as in the video see how you get on.
     
    KartikArora111 likes this.
  22. richardrl

    richardrl

    Joined:
    Jun 4, 2016
    Posts:
    17
  23. darklord886

    darklord886

    Joined:
    Jun 30, 2015
    Posts:
    1
    NullReferenceException: Object reference not set to an instance of an object
    Controller.SetCountText () (at Assets/Scripts/Controller.cs:39)
    Controller.OnTriggerEnter (UnityEngine.Collider other) (at Assets/Scripts/Controller.cs:34)
    Please Help!
    This error is driving me crazy. ca't figure it out.
    My code is
     

    Attached Files:

  24. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Did you fill in the variables in the Inspector?

    Instead of posting text files, you should post your code here using the proper tags.

    Sans titre-1.jpg
     
  25. Braveblacklion

    Braveblacklion

    Joined:
    Jun 7, 2016
    Posts:
    1
    Hey,

    I can't move the sphere. There is no checkBox for the script. (Speed is set to 100 skript is right).
    There is an addition Error "Clear on Play": The process can't access a File that is used by another process. How to fix that? (Script editor is closed an nowhere opened)
     
  26. KartikArora111

    KartikArora111

    Joined:
    May 13, 2016
    Posts:
    2
    The 3D issue got fixed automatically. I think it happened because i was trying to create a 2D project earlier.
    For the collision i added a box collider with negligible thickness.
    Thanks for the valuable info. :)
     
  27. silted1

    silted1

    Joined:
    Jun 9, 2016
    Posts:
    2
    I have this error which is making the ball not move in game mode I presume



    PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:15) To change the input settings use: Edit -> Project Settings -> InputArgumentException: Input Axis Horziontal is not setup.


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

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    If you click on the error does it give any further information?
    Does closing and reopening the editor do anything?
     
  29. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Have another look at the line indicated. You have accidentally misspelled "Horizontal".
     
  30. silted1

    silted1

    Joined:
    Jun 9, 2016
    Posts:
    2
    That's what you get for trying to learn Unity for the first time at 3am lol. Thanks...onto the next tutorial.
     
    OboShape likes this.
  31. olising

    olising

    Joined:
    Jun 12, 2016
    Posts:
    1
    Hi guys,

    I've been having the "ball not moving issue" and wanted to post my solution (I haven't read ALL the comments on this page forgive me if this has already been stated):

    By default my rigidity component added to my ball was set with the "Is Kinematic" option ON. It was not stated in the tutorial video that this option needed to be set on OFF.
    --> This is very displeasing by the way for I have been trying to fix this problem since last night, trying to delete my script and recreating it, reimporting etc
    Please think about these sort of defaults when making a tutorial video to avoid having new customers like me feel unsatisfied when observing a simple script not working.
     
  32. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    If you take a closer look at the video, you'll see that "is kinematic" is unchecked. This box is unchecked by default, so you probably put it on by accident. Happened to me. :)
     
    Last edited: Jun 12, 2016
  33. Whiteace53

    Whiteace53

    Joined:
    Jun 20, 2016
    Posts:
    1
    in the tutorial "moving the player" the ball does not move when I use the arrow keys
    i have rigid body on the player, it is not kinetic, there are no errors and speed = 10 please help




    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 movment = new Vector3(movehorizontal, 0.0f, moveVertical);
    21.  
    22.         rb.AddForce(movment * Speed);
    23.     }
    24. }
    25.  
     
    Last edited: Jun 20, 2016
  34. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    One thing to be aware of is that C# is caSe sensiTive. start and Start are different.

    If you look at your two methods they are both lower case, they should be Start() and FixedUpdate() in that case.
     
  35. the truth

    the truth

    Joined:
    Jun 21, 2016
    Posts:
    1
    Why the video can't be played? Just blank?
     
  36. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    Which one?
     
  37. yogsdog1000

    yogsdog1000

    Joined:
    Jun 21, 2016
    Posts:
    2
    hello, ive been attempting the role a ball tutorial and i thought i was doing quite well, but after i finished the script, i couldnt get the ball to move. i think the script is right, but im not completely sure, because after i finished the script there was no option for speed in the editor, here is my script
    using UnityEngine;
    using UnityEngine.UI;

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



    can you guys notice if ive written this wrong?
     
  38. yogsdog1000

    yogsdog1000

    Joined:
    Jun 21, 2016
    Posts:
    2
    its ok i figured it out
     
  39. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    Code (CSharp):
    1. void OnTriggerEnter(Collider other)
    2.     {
    3.         other.gameObject.CompareTag ("Pick Up");
    4.         {
    5.             other.gameObject.SetActive (false);  
    6.             count++;
    7.             CountTextFunction ();
    8.             if (count >= 16)
    9.             {
    10.                 win.text = "You Win";
    11.             }
    12.         }
    13.     }
    When player collides with PickUp objects, PickUp objects will be deactivated. However, I think we have to destroy "PickUp" objects. Destroying is better than Deactivating for optimization performance . Is not it?
     
  40. ladyonthemoon

    ladyonthemoon

    Joined:
    Jun 29, 2015
    Posts:
    236
    It's a tutorial. Tutorials cover different ways of doing things. In one of the videos, Adam mentions "destroy" but specifies that this time we would use "SetActive (false)". It's easy to understand why. this tutorial is meant for beginners amongst beginners; people who have no idea what "SetActive" relates to. After this tutorial, they'll know.

    In other tutorials, you'll be able to use "destroy".
     
    KAYUMIY likes this.
  41. SageFlare

    SageFlare

    Joined:
    Jun 25, 2016
    Posts:
    2
    Hello, currently I am receiving an error that states: Type 'Text' does not contain a definition for 'text' and no extension method 'text' of type 'Text' could be found.

    This is my code.

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;
    public Text countText;

    private Rigidbody rb;
    private int count;

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

    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("Pickup"))
    {
    other.gameObject.SetActive(false);
    count = count + 1;
    SetCountText();
    }
    }

    void SetCountText ()
    {
    countText.text = "Count: " + count.ToString();
    }

    }

    I would greatly appreciate any help that could be sent my way.
     
  42. BubblesMedia

    BubblesMedia

    Joined:
    Jun 26, 2016
    Posts:
    1
    I can't get my ball to move in the 2nd tutorial. I have the script correct. I know because I first wrote it word for word and checked, when my ball didn't move, I deleted the script and copy pasted the exact script given from the tutorial itself.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.  
    7.     public float speed;
    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. }
    I don't know why but I get thihs error message when I run the code Analysis:

    Warning CA1016 Add an AssemblyVersion attribute to 'Assembly-CSharp.dll'. Assembly-CSharp Active

    I don't know what that means and I don't know how to make the ball move. Help??
     
  43. SageFlare

    SageFlare

    Joined:
    Jun 25, 2016
    Posts:
    2
    Hmm, I don't see anything wrong with the script. It seems to be alright, so I'm going under the assumption that it's outside of it. The warning says something about the Assembly Version, so what I'm thinking is maybe that your Assembly Version is wrong. I'm new at programming too so this is all I can think of, but hopefully it helps you in your search for a solution. So yeah, just look up how to figure out if your Assembly Version is wrong or something similar.
     
  44. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Cant see anything glaring at me, is that the only error you were getting, was the script saved, have you tried removing and readding to player?
     
  45. balzua

    balzua

    Joined:
    Jun 28, 2016
    Posts:
    3
    Hi - thanks for the wonderful tutorial.
    I am working my way through now and I'm wondering about the scale of the walls and the scale of the ground object.

    If you set the scale values for the Ground to x = 2, y = 0, z = 2, how come in the video where you make the walls, you need to scale them to z = 20.5 to get them to be the same length in the z direction as the ground?

    Sorry if this has already been asked but I could not find a way to search through the forum thread.
     
  46. rishib11

    rishib11

    Joined:
    Jun 28, 2016
    Posts:
    1
    Hey I am new to Unity. I am trying the Roll A Ball game for the first time. I am using the personal edition of Unity. Can this game be developed with the personal edition? Or do I need to get the professional edition? Thanks for your help.
     
  47. KAYUMIY

    KAYUMIY

    Joined:
    Nov 12, 2015
    Posts:
    115
    You can create Roll A Ball game with the personal edition. In addition, you can do many things with personal edition more than you expected.
     
  48. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Not sure what that errors referring too, but if your not getting any errors in the Unity console the problem may not be with the code, but may be a setting for the player you have in the editor. couple of things to have a quick check of in the Editor.

    for the player, the Rigidbody in the
    Its down to the size of the primitives. A cube is 1 unity unit square, the ground primitive is a Plane. the Plane is I think 10 unity units square by default
     
  49. balzua

    balzua

    Joined:
    Jun 28, 2016
    Posts:
    3
    Thanks, this makes perfect sense.

    I am new to this as well, so I'm sorry if this isn't quite correct, but could you try changing the function at the bottom to use countText.Text instead of lowercase, countText.text

    So it becomes
    Code (CSharp):
    1. void SetCountText ()
    2. {
    3.      countText.Text = "Count: " + count.ToString();
    4. }
     
  50. greatness

    greatness

    Joined:
    Feb 20, 2016
    Posts:
    199
    Is it just me, or is some of the lessons in ROll a ball set to intemediate level? I dont think they should be set to intermediate. They should be set to beginner.