Search Unity

Official Roll-a-ball Tutorial Q&A

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

  1. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    hehe, no worries least its working now.

    on the plus side, its something that you will check next time that needs something similar ;)
     
    Goby03 likes this.
  2. Yumetik

    Yumetik

    Joined:
    Nov 11, 2016
    Posts:
    3
    Hello!
    I ran into an issue at the last step of the tutorial. After building the game as a standalone windows app and launching the app, the player object never collect the Pick Up objects. The player object just go through the Pick Up objects and the counter is never incremented... this is very strange because this issue doesn't happen in Play mode. The behavior in Play mode is correct, Pick Up objects are deactivated, counter is incremented and the game ends correctly.
    How can the behavior be different in the standalone app and in the Unity play mode? Do you have an idea how to fix that?
     
  3. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    if you could, try removing and readding the tag attached on the pickups.
    when you build, try building as a development build, just to see if theres any difference.
    and theres no errors/warnings in the console at all?
     
    Yumetik likes this.
  4. Yumetik

    Yumetik

    Joined:
    Nov 11, 2016
    Posts:
    3
    I rebuilt as a development build and there was indeed an error in the console. Something like "Pick Up" tag not defined and it was referencing this line of code:
    Code (CSharp):
    1. if(other.gameObject.CompareTag("Pick Up"))
    I double checked that the tag was correct (it works in Play mode) then I started to build it again but Unity crashed.
    After restarting Unity I relaunch the built and this time it was working... I might have stumbled on a bug, or something's funny with my config. Anyhow, thanks for your time!
     
  5. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    so the build is working ok now? yeah, ive seen it before where some things dont get carried through to build, like tags etc.
     
  6. Yumetik

    Yumetik

    Joined:
    Nov 11, 2016
    Posts:
    3
    Yes the build is finally working, restarting Unity after the crash fixed it :)
     
  7. cristi21_tgv

    cristi21_tgv

    Joined:
    Nov 7, 2016
    Posts:
    1
    Hi,
    Can I use the scripts from Roll-a-Ball tutorial for a commercial game? I have Unity Plus membership.
    Thank you
     
    Last edited: Nov 14, 2016
  8. TheMonkeyGru

    TheMonkeyGru

    Joined:
    Nov 16, 2016
    Posts:
    2
    My script wont work
     
  9. FreedomCereal

    FreedomCereal

    Joined:
    Nov 20, 2016
    Posts:
    2
    Hi, would like to know how to make it so that my ball resets or "dies" when it hits a specified object, or (at least) a way for to hit "r" to restart/reset any solutions?
     
    Last edited: Nov 21, 2016
  10. FreedomCereal

    FreedomCereal

    Joined:
    Nov 20, 2016
    Posts:
    2
    What part?
     
  11. dreammakercp

    dreammakercp

    Joined:
    Nov 27, 2016
    Posts:
    2
    Hi @Adam-Buckner,

    I've completed lesson 2 of 8 of the Roll a Ball game, however I'm still not able to move my Ball. Here's my code, am I missing something?

    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. }
     
  12. dreammakercp

    dreammakercp

    Joined:
    Nov 27, 2016
    Posts:
    2

    Never mind :). I found the issue. I had "Fixedupdate" instead of "FixedUpdate." I didn't capitalize the "U"
     
  13. mokech

    mokech

    Joined:
    Nov 30, 2016
    Posts:
    2
    hi! Whenever I add the Player Controlled script to the Inspector and play with the speed, it disappears after I undo play mode. Why is this and will it only be accessible for play mode?
     
  14. mokech

    mokech

    Joined:
    Nov 30, 2016
    Posts:
    2
    I figured out my last issue - now the "You win!" doesn't actually pop up it just stays the whole time. What does this mean?
     
  15. GlebK

    GlebK

    Joined:
    Dec 3, 2016
    Posts:
    1
    Hello,
    I just tried to make camera follow the ball, I copied the script as it shows in the tutorial, but the camera now sticks to the player with 0 distance between them. how can I adjust that?
     
  16. leomuteki

    leomuteki

    Joined:
    Dec 14, 2016
    Posts:
    2
    Hello everyone!,
    What is the difference between:

    this.gameObject.setActive(false);
    and
    this.enabled(false);

    For computer-resource conservation, am I able to disable/deactivate and then enable/reactivate later with both?
     
  17. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
  18. Alexandra112

    Alexandra112

    Joined:
    Dec 16, 2016
    Posts:
    1
    Roll-a-ball is cool project, and I use sometimes https://answershark.com/ . Here you will get fast and qualified answer to your question.
     
  19. markreed

    markreed

    Joined:
    Dec 19, 2016
    Posts:
    2
    I'm using version 5, and I'm having the "ball won't move" problem, too.

    Here is my code at the point where movement and speed are introduced:
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class controllmovement : MonoBehaviour
    {

    public float speed = 10;
    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);
    }
    }

    I started from scratch and the problem persists. Can you offer any advice.
     

    Attached Files:

  20. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    markreed,

    the only thing I see different from my script is you have fixedUpdate and I have FixedUpdate (capital F). Try changing that and see if it works.
     
    markreed likes this.
  21. markreed

    markreed

    Joined:
    Dec 19, 2016
    Posts:
    2
    @Ryeath ,I'll be damned. C# is pretty case sensitive and I didn't catch it in the debug phase. Thanks a million.
     
  22. Matthew_237

    Matthew_237

    Joined:
    Dec 22, 2016
    Posts:
    1
    Okay, so my roll-a-ball works perfectly in unity but once it's built, the player no longer collides with the pick up items and rolls straight through. I tried writing "collision" to the console (and as far as I can gather that should also write to the output_log file once the project is built) and this worked fine in unity again, but not in the build after I rebuilt it. That leads me to believe that my pick up items no longer have the "Pick Up" tag after building, however I have no idea how to check this and also no idea how to fix it. I checked my PlayerController class and it is identical to the one used in the tutorial and all my pick up objects are tagged with "Pick Up" and have Is Kinematic selected in unity. Anyone have anymore ideas to fix?
     
  23. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    There is a mention in the FAQs
    https://unity3d.com/unity/faq
     
  24. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Possibly have a work through the space shooter tutorial, this uses the restart button mechanic. should give a good idea on how you can merge the two concepts.
     
  25. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    couple of things you can check.
    have you set the winText in your Start() method of the PlayerController script to be empty?
    Code (CSharp):
    1. winText.text = "";
    also, just have a look in the SetCountText() method to see if theres anything wrong with checking the actual win condition logic.

    maybe even have another run through the Displaying score and text section.
    https://unity3d.com/learn/tutorials...rial/displaying-score-and-text?playlist=17141
     
  26. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    in the CameraController script, have you capitalised the Start() method with a capital S?

    as this sets the offset value, if its 0 then the position set in the LateUpdate() will be the position of the player + 0.
     
  27. Stiles96

    Stiles96

    Joined:
    Dec 24, 2016
    Posts:
    1
    I just finished Setting up the Play Area tutorial video,and it all worked perfectly until i tested in local mode and realise that the ball is not rotating...is there a problem with the camera or i messed up something with the ball?
     
  28. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    So does it move when testing in the editor, but not working when you build it?
     
  29. Tahir-ibne-Ali

    Tahir-ibne-Ali

    Joined:
    Jan 20, 2014
    Posts:
    6
    Hi.
    I completed that Whole learning Project without any error. But i have 1 question. Please tell me name of the respected instructor who has taught us, this Roll a ball game tutorial?
     
  30. Criticalnar

    Criticalnar

    Joined:
    Dec 27, 2016
    Posts:
    3
    My private Rigidbody rb; has been working fine but it randomly just started saying member modifier 'private' must precede the member type and name
    what happened??
     

    Attached Files:

  31. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    thats the camera script you posted, whats the error you are getting, im assuming that when you say its the Rigidbody, was it on the PlayerController script?

    rather than attaching files, can you post the script that is getting the error using code tags please ( its the top bar when you post as the Insert icon, then select code), and the error message please.
     
  32. Criticalnar

    Criticalnar

    Joined:
    Dec 27, 2016
    Posts:
    3
    Code (CSharp):
    1.  using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;  
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.  
    8.     public float speed;
    9.     public countText
    10.  
    11.     private Rigidbody rb; *Member modifier 'private' must precede the member type and name*
    12.     private int Count;
    13.  
    14.  
    15.     void Start ()
    16.  
    17.     {
    18.         rb = GetComponent<Rigidbody>();
    19.         count = 0;
    20.         SetCountText ();
    21.     }
    22.  
    23.     void FixedUpdate ()
    24.     {
    25.         float moveHorizontal = Input.GetAxis ("Horizontal");
    26.         float moveVertical = Input.GetAxis ("Vertical");
    27.  
    28.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    29.  
    30.         rb.AddForce (movement * 10);
    31.     }
    32.  
    33.         void OnTriggerEnter(Collider other)
    34.     {
    35.         if (other.gameObject.CompareTag ("Pick Up"))
    36.         {
    37.             other.gameObject.SetActive (false);
    38.             count = count + 1;
    39.             SetCountText ();
    40.         }
    41.     }
    42.  
    43.     void SetCountText()
    44.     {
    45.         countText.text = "Count: " + count.ToString ();
    46.     }
    47. }
     
  33. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Looks like you are missing a semi Colon at the end of line 9
     
  34. Criticalnar

    Criticalnar

    Joined:
    Dec 27, 2016
    Posts:
    3
    When I put the semi colon at the end of line 9 and new error comes up saying "Invalid token ';' in class, struct, or interface member declaration"
     
  35. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Theres the script that ive ammended, should work now.

    couple of things that you can watch out for in future..
    Ive commented what ive changed..
    if in doubt, compare it to what you had to check changes.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour
    6. {
    7.  
    8.     public float speed;
    9.     // missed out variable type 'Text' here and the semicolon here at the end
    10.     public Text countText;
    11.     //*Member modifier 'private' must precede the member type and name* // is for commenting a line * just confuses compiler
    12.     private Rigidbody rb;
    13.     // upper case C here and the variable you are  using in Start has a lower case, so changed this to lower case c
    14.     private int count;
    15.  
    16.  
    17.     void Start ()
    18.  
    19.     {
    20.         rb = GetComponent<Rigidbody>();
    21.         count = 0;
    22.         SetCountText ();
    23.     }
    24.  
    25.     void FixedUpdate ()
    26.     {
    27.         float moveHorizontal = Input.GetAxis ("Horizontal");
    28.         float moveVertical = Input.GetAxis ("Vertical");
    29.  
    30.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    31.  
    32.         rb.AddForce (movement * 10);
    33.     }
    34.  
    35.     void OnTriggerEnter(Collider other)
    36.     {
    37.         if (other.gameObject.CompareTag ("Pick Up"))
    38.         {
    39.             other.gameObject.SetActive (false);
    40.             count = count + 1;
    41.             SetCountText ();
    42.         }
    43.     }
    44.  
    45.     void SetCountText()
    46.     {
    47.         countText.text = "Count: " + count.ToString ();
    48.     }
    49. }
     
  36. Althemier

    Althemier

    Joined:
    Jan 5, 2017
    Posts:
    2
    The ball wont move, i have follow all in the videos but the ball still wont move.
    Here is the code that i was typing:

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

    public class PlayerMovement : MonoBehaviour {

    private Rigidbody rb;

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

    void FixUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertikal");

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

    rb.AddForce(movement);
    }
    }
     
  37. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    I see two errors.

    First it should be FixedUpdate, not FixUpdate as you have.
    Second you misspelled Vertical in your input statement.

    Try fixing those and see if it helps.
     
    OboShape likes this.
  38. Althemier

    Althemier

    Joined:
    Jan 5, 2017
    Posts:
    2
    thanks a lot. it works. I even dont notice the misselled
     
  39. LighterDoesIt

    LighterDoesIt

    Joined:
    Jan 6, 2017
    Posts:
    1
    I'm also having issues getting my ball to move. Using Unity 5.5

    Here is my script:

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

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

    }
    }

    /edit: In the Unity Inspector I noticed the field speed was set to 0...I changed that to 3, and now whenever i push an arrow key the ball just goes nuts...like an airplane in an out of control spin until it gradually slows to a stop... I think i laugh here...

    /edit2: figured it out. I had the camera added under the player, when i put it above the player object in the hierarchy i was able to watch my ball move....
     
    Last edited: Jan 6, 2017
  40. Deleted User

    Deleted User

    Guest

  41. XonaGames

    XonaGames

    Joined:
    Aug 26, 2016
    Posts:
    2
    CTRL-' is opening Team Explorer inside of Visual Studio on my PC. It was working yesterday, properly opening a search on the Unity webpage. I searched the shortcut settings in Visual Studio and CTRL-' is set to load Team Explorer. Is this the default? Does the Unity version change the default setting? I am curious why this setting exists and how to set it back. The search shortcut is so useful, I wish to continue to use it.
     
  42. danielberdea95

    danielberdea95

    Joined:
    Jan 8, 2017
    Posts:
    2
    hi, i can't make this ball move. IN the unity editor it appears
    The referenced script on this Behaviour is missing!
    The referenced script on this Behaviour (Game Object 'Player') is missing!

    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:

  43. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Evening,

    within Unity, the script name and the class name must match exactly if it is dealing with MonoBehaviours, otherwise it will not compile.

    so looking at your script name it is 'PlayerControl.cs' and the class name in the script is 'PlayerController'.

    to get this working, rename the script to match, so it would need to be 'PlayerController.cs'

    You may have to remove the script from the player in the inspector and re-add it to get it to take the change.
     
    danielberdea95 likes this.
  44. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    have a read of this, see if it helps you out any to get the settings changed back.
    https://forum.unity3d.com/threads/getting-ctrl-to-work-within-vs.372584/
     
  45. danielberdea95

    danielberdea95

    Joined:
    Jan 8, 2017
    Posts:
    2
    Yea i just saw that, thanks for reply, really apreciatte
     
  46. ReinoldJudd

    ReinoldJudd

    Joined:
    Jan 11, 2017
    Posts:
    7
    When I try to edit the script, I get:

    Could not load project 'ball tutorial.csproj' with unknown item type '{E097FAD1-6243-4DAD-9C02-E9B9EFC3FFC1}'

    Anyone know what that's about?
     
  47. Run_TMC

    Run_TMC

    Joined:
    Jan 12, 2017
    Posts:
    1
    Doing this tutorial on both a PC and a Mac. On the Mac, when I duplicated the Background Material, I was not able to rename it. When I duplicated it on a PC, it was ready to be renamed the moment I made the duplication. But, once it is renamed, I don't see a way to rename it again. I'll check again on my Mac at home tonight to see if that is how it behaves there too.
     
  48. marroon69

    marroon69

    Joined:
    Jan 13, 2017
    Posts:
    3
    Quick question? I installed the latest version of the tool and then started the Rollaball tutorial. But I do not get very far...when I add the plane and sphere they do not seem to have any color, they are all black. Not sure if this makes any sense...it just looks so different than the tutorial I thought I would ask. It is the base default material, but there is no color or shading. The game view has no camera rendering (the message in the view window) so it is also black. Is there a different tutorial I should follow first? I have tried to change things but I am not finding anything. I can post a pick if that would help. Sorry, I am pretty new and thought I would ask.
     
  49. Deleted User

    Deleted User

    Guest

  50. marroon69

    marroon69

    Joined:
    Jan 13, 2017
    Posts:
    3
    Thank you! I have gone through all the Interface & Essentials. But it seems that when the tutorial creates a new project the Main Camera and Directional light are included in the new project. By default mine does not that was my confusion, I added them and now it makes more sense.