Search Unity

Unity 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,670
    Our tutorials are set up to teach you the coding you need to know as you go along.

    There are many lessons in the learn site (unity3d.com/learn) that will help you learn the coding you need as well.
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    The canvas is the size it's meant to be. Please see the various UI lessons in the Learn tab. The size of the canvas is 1 pixel == 1 unity unit, so it will appear very large when compared to the scene view. You are not really expected to view both at the same time and the UI can be turned off in the editor if it's distracting when working on scene objects.
     
  3. DreamBliss

    DreamBliss

    Joined:
    Jul 10, 2014
    Posts:
    7
    What about not seeing the text? I changed the color and positioned it above the player.

    Thank you for replying to all of our posts and keeping an eye on this.
     
  4. gopixus87_unity

    gopixus87_unity

    Joined:
    Sep 12, 2017
    Posts:
    3
    Hello,

    I'am trying to make this very basic tutorial and on 2 step i have a problem. When I'am press play and try to move ball with arrows on keyboard, nothing happen and appear message "Display 1 No cameras rendering" I have 2017.1.1f1 version of unity. There is my script code:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class PlayerController : MonoBehaviour {
    6.  
    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.  
    21.         rb.AddForce (movement);
    22.     }
    23.  
    24. }
    25.  
    After 30 min of learning first problem not good :(
     
  5. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    The best work few when working in the UI is to swap the mode into 2D and to select the main canvas and "frame selected" (use the menu, use the F key while the cursor is in the scene view, or double click on the canvas in the hierarchy). This will show you the entire canvas and all of the UI elements.

    Does this help.
     
    organicvr likes this.
  6. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    If you have the errors "No Cameras Rendering" this means you might not have a camera or the camera is disabled.

    At this stage it might be easier to restart the tutorial.

    If you don't want to do that, you need to investigate whether you have a camera in your scene or if the camera has been disabled.
     
  7. mc3

    mc3

    Joined:
    Mar 27, 2016
    Posts:
    19
    I found the bouncy physic material through a tutorial when I googled bouncing ball unity ... that was cool. I was able to get the ball to bounce around better this way. Learned a bit about the .. was it friction.. although it was a little confusing how the max, average and minimum values calculated against each other.

    So I have it bouncing off the walls but I wanted to modify it in a way that it wouldn't let me. With the max value of 1, I wanted to give it a little boost when it hit the wall, say a value of 1.2. It would revert to 1.

    By detecting a collision, can I create this additional physics force easier? Or is there a workaround to the bouncy physics material method?
     
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    IIRC a bouncy value of 1 will be 100% bouncy. EG: the ball will lose no energy. If you dropped a ball that had no drag (so no air resistance) with a bouncy material of 1, the ball should drop and then bounce back to the original height it dropped from. This would go on forever, as the system loses no energy. A bouncy material less than 1 returns some, but not all, or the energy. Experiment until you get it correct. Now, I can't remember what happens if you have the physic material on both the ball and the floor... I'm not remembering if this combined to ADD energy or not. You'll have to try it out!
     
  9. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Maybe I'm misinterpreting what you are trying to do.

    Can you tell me from scratch what the desired final outcome is?
     
  10. gopixus87_unity

    gopixus87_unity

    Joined:
    Sep 12, 2017
    Posts:
    3
    I just install older version 5.6.3 and everythings looks better and works fine. I think is no diference from 5 to 2017 to noob like me so I wanna use 5.6.3.
     
  11. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    From my understanding of the technology - changing from 2017 to 5.6, should not fix a missing camera issue.

    If it _does_, can you submit a bug report?

    Now, if you were working on the project in 2017.x and reimported it into 5.6.x - there is the chance the re-import process may change something. If your project is now working as expected, try opening it in 2017.x and see if stays that way.

    It should.
     
  12. WildGiller

    WildGiller

    Joined:
    Sep 12, 2017
    Posts:
    2
    I am stuck at the "moving the player" in the C# script component of the tutorial.

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

    The above is entered as per the video and saved in the script.
    But when I go back to the Unity I'm getting a compiling error.
    "No MonoBehaviour Scripts in the file or their names do not match the file name"

    I am running Unity 2017.1.1f1

     
  13. Bakerfield

    Bakerfield

    Joined:
    Jul 2, 2017
    Posts:
    2
    Hello!

    Yes. When I updated Unity to version 5.6.3p1 and compiled the project again it worked fine. Maybe the older version had a bug. I am using Windows 10 pro 64 bit. My input device is a common Microsoft natural ergonomic keyboard 4000. No extras (other than a 3d connexion space navigator, which I suppose doesn't have anything to do with the game), no unusual or deprecated drivers.

    Like I said, all fine now, thanks!
     
  14. Big_Walt

    Big_Walt

    Joined:
    Sep 15, 2017
    Posts:
    1
    My current problem is that after building the app and executing the app my "count text" disappears and I go through the cubes without triggering them. here is the code.
    Capture.PNG
     
  15. GrimGriefer

    GrimGriefer

    Joined:
    Sep 16, 2017
    Posts:
    1
    I checked out a few of the video tutorials (love them! hope they continue to grow!) and started this tutorial straight from unity's launcher "Learn" tab, after downloading it. The first thing the tutorial tells you to do is to save the scene, however, the project is in some temp folder location and will not allow saving your scene in the same location it points you to, prompting an error popup that it must be saved to the asset folder. clicking the close unity button and then clicking "keep" button prompts me to save in Documents folder. I make a folder for the project in Documents and it seems to have relocated (or at least duplicated) the files in the temp folder to this new folder. After which I am now able to save the scene when I reloaded it from the Projects tab.

    I'm assuming your first attempt to save scene, when first launched from the unity "Learn" tab, points your default save location in a place not allowed, which confused me for a bit. It would be nice if it pointed you to the correct location when first launched.

    First time using the Learn section. Using Windows 10
     
  16. softwarepoet

    softwarepoet

    Joined:
    Jun 9, 2016
    Posts:
    1
    Thanks for the tutorial! Everything went great, until... Build for PC... It builds fine, but when I run it, the ball races to the upper-left corner. I tried the normal stuff: Cold Shutdown + Reboot, build again, and same result. The game plays fine inside the unity editor.

    What steps can I take to try to root cause the issue?
     
  17. AlfredvanRaal

    AlfredvanRaal

    Joined:
    Feb 27, 2017
    Posts:
    5
    How to stop fixed eye in the scene view

    am doing some tutorials to start working with Unity. I found a problem in the scene view. It very difficult to zoom and right the way i want to. The "zoom/eye" button got stuck (Zie image of the eye). I don't know how to deselect it. My mouse becomes an "eye" with four squares below it. Its very unhandy to get the view i want to.

    Hope someone can help me deselect this.
     

    Attached Files:

    • Oog.JPG
      Oog.JPG
      File size:
      8 KB
      Views:
      308
  18. brycenbfalzone

    brycenbfalzone

    Joined:
    Sep 22, 2017
    Posts:
    1
    Hi so for some reason every time I go to edit a script Virtual Studio starts. I don't think it's a big problem, but I can't open up two scripts because the second one doesn't connect to Unity. Also, I experienced some problems with not being able to change the ball's speed and it gave me errors saying that the script has two different formats or something. I can't also pull up the reference page on the Unity website. I guess my question is how do I get back to the original Script editor and if I can't do Virtual Studio work the same with Unity?
     
  19. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    You can go into the Unity Editor and under settings change your scripting editor to Monodevelop.

    At the time that these tutorials were created, the default code editor for Unity on Mac and Windows was Monodevelop. Now there are additional options, including Visual Studio. In VS, you can create a link between the code editor and the Unity documentation, but you will have to set this up yourself. Best, would be to google for the most recent way of doing this.

    Hope this helps!
     
  20. ninjalunchboxninja

    ninjalunchboxninja

    Joined:
    Sep 23, 2017
    Posts:
    1
    I wrote out the code in step two, set the speed value to 50, no errors, but the ball won't move. Can you tell me what's wrong?
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    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.     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.  
    21.         rb.AddForce (movement * speed);
    22.  
    23.     }
    24. }
     
  21. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    I don't see any obvious issues with the code upon a quick scan...

    Do you have any errors in your console?

    Can you send us a screenshot of the GameObject?
     
  22. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Is your script file named "NothingSelected.cs"? That's what is appears to be.

    Your script name should be the same as the class name.

    Your class name is "PlayerController" so your script name should be "PlayerController.cs".
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    The "going through the cubes" issue may be related to tags. Go to your tags and layers panel and make sure that they are properly defined - I suspect they are missing. And then make sure that the tags are properly assigned to the prefabs.

    Can you give us any more information related to the UI text? I don't have enough information to suggest a fix.
     
  24. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Odd - sounds like you are getting random input data from somewhere...

    Can you give us any more information?
     
  25. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    The eye with 4 squares below it means you are in fly through mode. Usually is is only true when holding the right/context mouse button. This means you can use the wasd keys to fly through the scene.

    You can look this up in the manual for more information.

    You should be able to deselect that or not use the right mouse button.

    I assume you have restarted Unity and your machine and made sure that you are on the most recent version and all of that?
     
  26. dflipb

    dflipb

    Joined:
    Sep 24, 2017
    Posts:
    1
    OMG!!!! THANK YOU!!! I had the same problem!!! Freaking capital S!!!
     
  27. viveksaikode

    viveksaikode

    Joined:
    Sep 29, 2017
    Posts:
    1
    the camara movement is not working for me,someone pls help :(
     
  28. EvilElephant

    EvilElephant

    Joined:
    Sep 29, 2017
    Posts:
    3
    Hello,
    when i'm testing the game in Unity, everything works fine, but when i build it, and try to play, i can't pick up collectible objects. I just go trough them. :/
     
  29. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Please check previous posts #1476, #1482, #1485, #1490, #1493 and #1523 for possible solution

    Please note that the tags are case sensitive and must be identical in both the game object AND the C# code
     
    EvilElephant likes this.
  30. EvilElephant

    EvilElephant

    Joined:
    Sep 29, 2017
    Posts:
    3
    After I restarted Unity and build game again, it works. Strange. I didn't change anything. Only thing that's changed is that the tag I wanted to remove needed restart for complete removing it.

    Thanks anyway :D
     
  31. Jenetics

    Jenetics

    Joined:
    Oct 9, 2017
    Posts:
    1
    I came here because of the same issue, works fine in play mode but goes through without collision after building on windows. When following the tutorial I removed a tag that I had in error but tags aren't removed until you restart Unity, so I ended up with several tags like so:

    Tag 0 (Removed)
    Tag 1 (Removed)
    Tag 2 Pick Up

    When restarting Unity those removed tags are actually removed and the list is updated to:

    Tag 0 Pick Up

    After restarting unity and building again it works. It seems that those removed tags do not interfere with playing in Unity but that they act funky when building.
     
  32. programer717

    programer717

    Joined:
    Oct 9, 2017
    Posts:
    12
    I'm having problems with roll a ball camera moving script I'm completely new to coding here's my script I went back and forth from https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial/moving-camera?playlist=17141 and my script so everything should be right

    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class camracontroler : MonoBehaviour {
    6.  
    7.     public GameObject player;
    8.  
    9.  
    10.     public Transform player;
    11.  
    12.  
    13.  
    14.     private Vector3 offset;
    15.  
    16.     // Use this for initialization
    17.     void Start () {
    18.  
    19.         offset = transform.position - player.transform.position;
    20.        
    21.     }
    22.    
    23.     // Update is called once per frame
    24.     void LateUpdate () {
    25.         transform.position = player.tranform.position + offset;
    26.    
    27.     }
    28. }

    I'm pretty sure I have the newest version of unity but I'm not sure.
    :)

    [code tags added by moderator - please use code tags!]
     
    Last edited by a moderator: Oct 16, 2017
  33. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    358
    I can't move the ball. I've made this tutorial like 2 times before and It worked at the first time. But now it just doesn't work. And I don't know what am I doing wrong. I have set the speed to 10 and still doesn't work.



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

    Attached Files:

  34. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Try removing
    public Transform player;
    since you've already (correctly) defined "player" with the line
    public GameObject player;
     
  35. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    The only thing I see is the asterisk in the hierarchy window, so perhaps changes you've made havent been applied.

    So, try this:
    save the scene, save the project, exit unity.
    restart unity and try again.

    Also, make sure there are no errors on the console log
     
  36. DaddyDahn

    DaddyDahn

    Joined:
    Oct 10, 2017
    Posts:
    2
    In the "Moving the Player" part, I changed
    Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    to
    Vector3 movement = new Vector3 (moveHorizontal, moveHorizontal, moveVertical);

    Why doesn't the ball go flying upwards when moved left or right?
     
  37. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    358
    I saved and restart Unity 2 times. the problems persist. I don't have any errors in the console either.
     
  38. BrewNCode

    BrewNCode

    Joined:
    Feb 17, 2017
    Posts:
    358
    Maybe because of gravity.
     
  39. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Ah well, A for effort.
    Lets add 3 debugging statements just to confirm we're not crazy.

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

    TheWiker

    Joined:
    Oct 10, 2017
    Posts:
    1
    Hey guys!

    I'm struggling to get the script running, particularly where we try to implement OnTriggerEnter.

    I have the code exactly as the tutorial has it, but it still has problems with other, void not being used correctly, OnTriggerEnter being declared but unused, etc. Seems like the entire code block has problems.
    I am running Unity 5.1 ish and patching to 5.5.4p4 as I type this post.

    Any ideas on how to resolve this issue? I can post more details of the compiler complaining if need be.

    Thanks in advanced!
     
  41. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Yes, please.
    Also, post your code, with the "code" blocks at the start and end.
    (Start "code" block is: [ code ], end "code" block is: [ / code ] without spaces)
     
  42. DaddyDahn

    DaddyDahn

    Joined:
    Oct 10, 2017
    Posts:
    2
    Yup, that was it. Thank you!
     
  43. unity_-lr-1bTAznCFcg

    unity_-lr-1bTAznCFcg

    Joined:
    Oct 15, 2017
    Posts:
    1
    plz help this doesn't work.
    I'm at tutorial pt. 2 at 13:00 and it doesn't work
    upload_2017-10-15_14-36-0.png
     
  44. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    remove the semi-colon on line 13,
    is: void FixedUpdate();
    should be: void FixedUpdate()
     
  45. s11pkn07

    s11pkn07

    Joined:
    Oct 15, 2017
    Posts:
    2
    I'm trying to do the scripting for the "count text" portion of the tutorial and for some reason I get an error with this particular line of code.

    countText.text = "Count: " + count.ToString ();

    It says "'UnityEngine.Texture' does not contain a definition for 'text' and no extension method 'text' accepting a first argument of type 'UnityEngine.Texture' could be found (are you missing a using directive or an assembly reference?)"

    I practically copy and pasted the "PlayerController" script and still get the error.
     
  46. s11pkn07

    s11pkn07

    Joined:
    Oct 15, 2017
    Posts:
    2
    Disregard, I found my mistake. The script auto filled "text" and changed it to "texture"
     
  47. williammrmustash

    williammrmustash

    Joined:
    Oct 16, 2017
    Posts:
    1
    in the Visual Studio whenever I highlight something and do "CTRL + ' " it doesn't bring up a help page inside of Visual Studio or a web page it just bringes up a " Team Explorer - Connect " thing
     
  48. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Can you please post more detailed information? We can't help you unless you give us some specifics. If you have having trouble, post your code using code tags and use screen shots of your current component setup.
     
  49. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Double check that your tags are correct.

    Open the tags and layers panel and make sure that they are properly defined and then check in the prefab to make sure that the tags are properly assigned.
     
  50. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,670
    Interesting... I'll try to find time to replicate this.

    If you can 100% replicate this, I'd love to know.

    We might be able to fix this.