Search Unity

Roll-a-Ball Tutorial Q&A [ARCHIVED]

Discussion in 'Community Learning & Teaching' started by Adam-Buckner, Mar 16, 2015.

Thread Status:
Not open for further replies.
  1. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is in the "known issues" in the Original Post:
    This should also be annotated on the video, so remember to turn annotations on!
     
  2. Patrel

    Patrel

    Joined:
    Mar 24, 2015
    Posts:
    6
    Go up to the top and click component>rendering>GUI Text
     
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Check the original post up at the top of the thread under Common Issues for what could be going wrong with your GUIText. If this is not the cause, please post again with the steps you've tried to fix this,
     
  4. BusyGrain

    BusyGrain

    Joined:
    Mar 27, 2015
    Posts:
    3
    This is the first scripting that I have done. In the video 'Roll a Ball' 03 - Moving the player at 4:30 I'm not sure what happens when the text gets highlighted and the bit just after that.
    Can somebody help me please?
     
  5. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you be more specific? What is the part if the project that's causing you trouble?
     
  6. BusyGrain

    BusyGrain

    Joined:
    Mar 27, 2015
    Posts:
    3
    He copies:
    void FixedUpdate ()
    {

    }
    and then replaces the text above. I think he used a hot key. I'm not sure what he clicked on to do this, is there a certain key combo, or did he simply just delete a section and then replace it? Thanks
     
  7. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Is this the part where update and fixed update are written and described, and then update is deleted? In this case it's for example purposes only and you can simply ignore update and use fixed update. This was done by selecting and deleting the text.
     
  8. BusyGrain

    BusyGrain

    Joined:
    Mar 27, 2015
    Posts:
    3
    OK, Thanks a lot, I didn't realise how simple that step was. Now I can progress. Thanks!
     
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    I'll just leave this here. It's an alternative fix to displaying text. One of the problems mentioned in the OP. It uses UI instead of the legacy GUIText.

    @Adam Buckner hope you don't mind I made this? Answers was getting a bit flooded with the question back when 4.6 came out.

    http://youtube.com/watch?v=IViD5G2ucNs
     
    Socrates likes this.
  10. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    No. No,prob's. I'm almost done with a re-created updated Roll-a-ball project for Unity 5. Should be done by mid-week. This will take the pressure off.

    Both Roll-a-ball and Space Shooter are annotated with the solution to the UI issues, but either people don't have annotations on, or they don't read it!
     
    Specht Computing likes this.
  11. KingfisherWyvernStudio

    KingfisherWyvernStudio

    Joined:
    Oct 5, 2011
    Posts:
    324
    In case they don't have it on, perhaps it's an idea to include a message about the need to set annotations "on" in the introduction text above the video? Maybe people aren't aware they can turn it on. I know I wasn't even aware of the existence of the annotations function until I just read here :)
     
  12. Socrates

    Socrates

    Joined:
    Mar 29, 2011
    Posts:
    787
    *joke* You give us a video and you expect us to read? That's too complicated. *joke*

    More seriously, I can think of two reasons why annotations would not be visible:

    First, because many YouTube videos spam you with tons of annoying annotations and so keeping them turned off is a defense mechanism. I've had videos where I could not see what the video was showing because there were so many popups.

    Second, because for some of us, streaming the entire video to hard drive and then watching it works much more smoothly. Not only does this allow me to jump forward and backward in the video as needed, since YouTube gets grumpy sometimes when I try to back up 10 or 20 seconds to have something repeat, drawing from the hard drive also avoids play issues for intermittent poor ISP connections.


    @Adam Buckner, If you are going to add annotations with solutions to the videos, could they also be added as notes below the video? Put them in a block above where the code samples would go. Nothing fancy; Just copied and pasted bits like the fixes that are being put at the tops of the various tutorial support threads in the Teaching forum.

    To be even more obvious, put a note about them at the end of the description text above the video, and probably a note on the main project page telling people to look for annotations on all videos as they may have been updated.
     
  13. SamClay

    SamClay

    Joined:
    Mar 31, 2015
    Posts:
    2
    How do i fix this Assets/Scripts/PlayerController.cs(13,45): error CS8025: Parsing error
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    D
    That really depends upon what you've done wrong.
     
  15. TimberLimber

    TimberLimber

    Joined:
    Mar 31, 2015
    Posts:
    5
    Hello,

    my ball does not move after I entered the first code. I get no error messages, the script is attached to the ball and it's set on active. Any ideas what I might do wrong?

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

    Socrates

    Joined:
    Mar 29, 2011
    Posts:
    787
    Just looking at your sample code, you never give speed a value, so it will default to zero. This means you never move.

    You may have already given speed a value in the Inspector. If that is the case, try increasing the speed. A speed set too low is something I've seen a number of people run into problems with.
     
  17. TimberLimber

    TimberLimber

    Joined:
    Mar 31, 2015
    Posts:
    5
    Hello Socrates, thanks for your reply. I increased the speed to 100 but the ball still wont move.
     
  18. Socrates

    Socrates

    Joined:
    Mar 29, 2011
    Posts:
    787
    Do some quick testing to make sure your code is getting to the right place. Right before the AddForce() on line 17, put in:
    Code (CSharp):
    1. Debug.Log("Horizontal Input: " + moveHorizontal + " and vertical input: " + moveVertical);
    I am also not sure you want that comparison on line 16. Since a Vector3 is made of floats and comparing floats can be sketchy with equals, this seems an odd thing to have. It is not in the code I have from when I did the tutorial a while back. I do not see that it gains you anything.
     
  19. TimberLimber

    TimberLimber

    Joined:
    Mar 31, 2015
    Posts:
    5
    I added the line to the code and I now get some information on the bottom left. I can see that the system gets input as the value for Horizontal or Vertical change when I use the arrow keys, however the ball still does not move.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour {
    5.    
    6.     public float speed;
    7.    
    8.     void FixedUpdate()
    9.     {
    10.         float moveHorizontal = Input.GetAxis ("Horizontal");
    11.         float moveVertical = Input.GetAxis ("Vertical");
    12.        
    13.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    14.  
    15.         Debug.Log("Horizontal Input: " + moveHorizontal + " and vertical input: " + moveVertical);
    16.         GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
    17.         }
    18.     }
    19.  
     
  20. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Try: Debug.Log (movement.ToString ());

    I'd expect this to give you a value, but it is the final value moving the ball.

    You could also copy the full parameters of the AddForce line into a Debug.Log so you can see the full value of movement * speed * Time.deltaTime.

    Again, I expect this to work, as the code looks good, but it's worth a try to rule out any issues we've missed.

    Now...

    Is the script attached to the player game object?
    Is the game object active?
    Is the component enabled?
     
  21. TimberLimber

    TimberLimber

    Joined:
    Mar 31, 2015
    Posts:
    5
    Hello Adam, I tried the Line you suggested and the info I get is not extended to
    To your questions I can answer yes to all three of them.
     
  22. SamClay

    SamClay

    Joined:
    Mar 31, 2015
    Posts:
    2
    But i dont know what I've done wrong
     
  23. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Actually, I meant this line: AddForce(movement * speed * Time.deltaTime);

    So try:
    Code (CSharp):
    1. Debug.Log(movement.ToString() + speed.ToString() + Time.deltaTime.ToString());
    This will cram all the logged values together, so you could add text to separate them.
     
  24. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Sorry, I was being a bit cheeky, but: You gave us no information to work with, so I was sadly and annoyingly being just as minimalistic back.

    A parsing error simply means the compiler did not understand the code that was written and something was wrong. (Parsing error is easy to google!)

    You will need to give us more information, and probably post your code, for us to diagnose this issue.
     
  25. WardPeeters

    WardPeeters

    Joined:
    Mar 19, 2015
    Posts:
    25
    I was wrong the wrong keyboard settings for ny keyboard. Sorry about that!
     
  26. RonaldMctwister

    RonaldMctwister

    Joined:
    Apr 2, 2015
    Posts:
    2
    Just wondering. how can i make it so that every time the player(sphere) collects a cube, we get a sound feedback. and how can i make it so that i can change levels(scenes) after collecting all cubes? plz reply
     
  27. TimberLimber

    TimberLimber

    Joined:
    Mar 31, 2015
    Posts:
    5
    Hi Adam, still no luck on my end. Frustrating
     
  28. RonaldMctwister

    RonaldMctwister

    Joined:
    Apr 2, 2015
    Posts:
    2
    Ok i found out a way to change scenes after collecting all cubes, but now how can i make the cubes emit sound when collected. plz reply.
     
  29. umbaman

    umbaman

    Joined:
    Apr 3, 2015
    Posts:
    3
    Hello, with unity5 I can't make the camera follow the player.... here is my code for the CameraController script

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class CameraController : MonoBehaviour {
    5.  
    6.  
    7.     public GameObject player;
    8.     private Vector3 offset;
    9.     private Camera cam;
    10.     public float xposition;
    11.  
    12.     // Use this for initialization
    13.     void Start () {
    14.         cam = GetComponent<Camera>(); //this is a late adition, but this also doesn't work
    15.         //offset = new Vector3(transform.position.x, transform.position.y, transform.position.z);
    16.         offset = transform.position;
    17.     }
    18.  
    19.     // Update is called once per frame
    20.     void LateUpdtate() {
    21.         xposition = player.transform.position.x; //just for debugging purposes, this does not update, it stays zero
    22.         cam.transform.position = player.transform.position + offset;
    23.         //transform.LookAt (player.transform);  
    24.    
    25.     }
    26. }
    27.  
    28.  
    29.  
    I dragged and dropped the player to the relevant box in the CameraController script settings within the Inspector
    Any ideas?
     
  30. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    @RonaldMctwister as far as adding sound effects goes, its really something outwith the original scope of the tutorial i believe, and more a 'have a go and see' target for you to reach for. if you continue to the space shooter tutorial, sound is covered and you can expand on what you have learned in this tutorial. and maybe come back to this one, and expand it further with what you have learned.

    heres the audio part of the space shooter..
    http://unity3d.com/learn/tutorials/projects/space-shooter/audio

    (as a gotcha for sfx, if a gameobject is destroyed and a sound is playing at the same time, the sound will not continue, it will stop and get destroyed at the same time as the object, but this is covered in the space shooter tute)
     
  31. Socrates

    Socrates

    Joined:
    Mar 29, 2011
    Posts:
    787
    Line 20 is your problem. Spelling is the issue.
    LateUpdtate() should be LateUpdate().
     
  32. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Look into the audio class and audio.play in the docs.
     
  33. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I don't know why you have xposition? This doesn't look like it's doing anything right now, and I can't see the purpose of it in moving your camera.
     
  34. Specht Computing

    Specht Computing

    Joined:
    Apr 4, 2015
    Posts:
    2
    So how or better where do you turn on the annotation. I am new and cant find it in either settings or in the navigation.
    I am upset that no one just adds the completed files in the documentation, so new users see the difference. I am wasting so much time. I could do this in an hour was stuff up to date, I have spent hours now trying to get it running efficiently but I spend so much time updating the scripting from the video for current unity. It is no wander new users shy away from scripting if the tutorials arent even updated to actually enable you to learn.
     
  35. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    @SpechtComputing bAnnotation is a youtube thing....

    look at below image, click on the Cog icon in youtube video, and check the settings there (as below)
     
  36. KingfisherWyvernStudio

    KingfisherWyvernStudio

    Joined:
    Oct 5, 2011
    Posts:
    324
    Heya,

    When you open a (new) chapter, click on the video start button. The video will start. Next, click the pause button. On the right, next to the YouTuber logo you'll see a gear. Click that. On the top there's the option to turn Annotations on/off.

    Good luck!

    ETA: Ninja'ed by Obo :D
     
    OboShape likes this.
  37. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I'm sorry we are not quick enough for you. We only have two screen casters doing live training, persistent material and updating and creating projects. It's a tough call whether we give you new materials - like how to use the new lighting pipeline, keep you up to date with live material, create new projects, or update old ones.

    Roll a ball is being completely updated, others will be annotated, a few will be depreciated.

    All the projects that I have done are currently annotated.

    That note regarding annotations is because many people turn them off.

    As far as I know they are on by default, so we expect that if you can turn them off, you'll be able to turn them back on again.
     
    Specht Computing likes this.
  38. sampazzer

    sampazzer

    Joined:
    Apr 5, 2015
    Posts:
    1
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour
    6.     private Rigidbody rb;
    7.  
    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.  
    22.         rb.AddForce(movement);
    Hi I get the error message: An object reference is required for the non-static field, method or property for the line of code: rb.AddForce(movement)
     
  39. handyplayer13

    handyplayer13

    Joined:
    Apr 5, 2015
    Posts:
    2
    I just finished this tutorial with Unity 5. Everything works, but...

    About 10 seconds after the game started the ball rolls to the top.
    I am not pressing any buttons.

    The ground (plane) doesn't have any rotation.
    I don't know what else could be the reason.

    EDIT:

    The coordinates of the player change immediately, but movement is visible after about 10 seconds.

    Debug messages show that the movement vector always is (0,0,0).
    Removing the "AddForce" line prevents the ball from rolling to the top.
     
    Last edited: Apr 5, 2015
  40. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This:
    Code (CSharp):
    1. private Rigidbody rb;
    ... needs to be inside the brace after ": MonoBehaviour {", otherwise! it's not in the class definition.
     
  41. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Interesting. I'll take a look.
     
    handyplayer13 likes this.
  42. handyplayer13

    handyplayer13

    Joined:
    Apr 5, 2015
    Posts:
    2
    Thanks! I uploaded my project in case you need it.
     

    Attached Files:

  43. umbaman

    umbaman

    Joined:
    Apr 3, 2015
    Posts:
    3
    Geia sou re Socrates!!
    You were right!!
    Hahaha
    Thank you very much
     
  44. umbaman

    umbaman

    Joined:
    Apr 3, 2015
    Posts:
    3
    It doesn't do anything as far as moving the camera is concerned. It is there just for "debugging" purposes, to see if the LateUpdate function is working. Thank you for your interest, Socrates found the problem in my code.
     
  45. Specht Computing

    Specht Computing

    Joined:
    Apr 4, 2015
    Posts:
    2

    Well i dont have it turned off then.
    Thnk you for the work you guys do.
    Not unappreciative, just frustrated.
    I know you understand, especially cause you have to deal with people like me :)
     
  46. Mysterium

    Mysterium

    Joined:
    Apr 7, 2015
    Posts:
    1
    I built the web player for rollerball and put it on my godaddy web host. I hope this is ok. There is not a direct link; you have to know the actual path.
    I have the free Unity3d.
    Anyway, It works from IE on my windows 8.1 PC. However, it does not work on my older iPad.
    Question: Does this only work on Windows based systems? And if I were to have this work on other browser platforms would I need to rent the Pro version for a month?
    Sorry if this is not the right place for this.
     
  47. Deleted User

    Deleted User

    Guest

    How would I go about adding(and aligning) the text in unity 5? The canvas seems MASSIVE compared to the game, and therefore I cannot see any text via the camera.
     
  48. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    The Webplayer needs to be run in a "PC" browser, so should work on Mac, Linux and Windows. To run on iOS, you need to build directly to the iOS platform.

    For your other concerns: You can use Unity and our tutorial projects, build them and run the from any platform you choose. You can use any of our tutorial assets, code included, in any project you choose, even commercial ones.
     
  49. shadowalk

    shadowalk

    Joined:
    Aug 12, 2014
    Posts:
    1
    Hey guys. I'm currently in part 3 (Moving the camera - 03 - Roll-a-ball) and I think I've got everything working correctly except for one little thing. I had to do things a bit differently. When I dragged 'Player' from the Hierarchy menu to the Camera Controller script's Player box and I clicked on play, the camera isn't following my sphere character at all.

    I had to do this

    So instead of the Player game object, I tried dragging the Sphere object itself from the Hierarchy to the Camera Controller player box and it worked. The camera is following my sphere character. It worked but I had to do things differently. I was wondering what I did wrong that I had to do it differently and will it cause me problems in the future. Here's my script if it helps

    using UnityEngine;
    using System.Collections;

    public class CameraController : MonoBehaviour
    {
    public GameObject player;
    private Vector3 offset;

    void Start ()
    {
    offset = transform.position;
    }

    void LateUpdate ()
    {
    transform.position = player.transform.position + offset;
    }
    }

    Thanks guys! I'm using Unity 5 Personal on a Windows 8.1 PC.
     
  50. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
Thread Status:
Not open for further replies.