Search Unity

Official Roll-a-ball Tutorial Q&A

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

  1. Lamb7

    Lamb7

    Joined:
    Jun 26, 2017
    Posts:
    5
    it also says movement is not a thing
     
  2. Lamb7

    Lamb7

    Joined:
    Jun 26, 2017
    Posts:
    5
    or moveHorizontal so nothing is working
     
  3. Lamb7

    Lamb7

    Joined:
    Jun 26, 2017
    Posts:
    5
    How do i fix it.....
     
  4. kajes

    kajes

    Joined:
    Jun 25, 2017
    Posts:
    6
    Could you post your code here, so we can inspect it properly. Remember to use the code tags when pasting in code here.
     
  5. XEthanO

    XEthanO

    Joined:
    Jun 29, 2017
    Posts:
    4
    pressing a direction key adds a force to the rigid body. How would I make the ball slow down all by itself? I can't look at rigidbody and find the force that is already on it, and subtract or divide anything from it. So, how would it be done?
    thanks
     
  6. kajes

    kajes

    Joined:
    Jun 25, 2017
    Posts:
    6
    Have you tried changing the "Drag" and "Angular Drag" properties on the Rigidbody component?
    https://docs.unity3d.com/Manual/class-Rigidbody.html
     
  7. XEthanO

    XEthanO

    Joined:
    Jun 29, 2017
    Posts:
    4
    Not exactly what I wanted, but interesting. I want to read the value of whatever the force currently is on the rigid body.

    I have another question: I want to detect when the ball "collides" (rests upon) a plane. How does one do that in Unity? I know about OnTriggerEnter, and the player already has a rigidbody on it, but the script isn't detecting collisions with planes. Why not?
     
  8. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon,

    Like @kajes has mentioned, since the ball is using the physics system, its behaviours will change based on physics properties and external physics forces applied to it. ( like angular drag, gravity, etc)

    increasing the Angular drag will slow the ball down over time as it would naturally if no other forces are present (like holding the movement buttons down)

    but if you want to look at the properties of the Rigidbody, check out the scripting reference, you can read what values it has, like velocity, angular velocity, mass etc.
    https://docs.unity3d.com/ScriptReference/Rigidbody.html (top bit)


    with regards to the collisions, within 3D theres a couple of ways to check collisions.
    you already mentioned Triggers, whereby these dont have any physical interaction, and you have Colliders (non triggers). the colliders that are not triggers have a physical presence in the scene and allow for physics interactions.

    theres a few different callbacks for them, say for planes, you can check if its in constant contact with the surface, using OnCollisionStay, theres a few of them, you can read here
    https://docs.unity3d.com/ScriptReference/Collider.html

    hope that helps a bit.
     
  9. Bakerfield

    Bakerfield

    Joined:
    Jul 2, 2017
    Posts:
    2
    Hello!

    I have just completed the roll-a-ball-tutorial. Everything works fine when I use the "play"-button. But when I build the exe the player-ball starts moving as soon as I start the game. It rushes into the upper left corner and stays there. I can move it with the s- and d-keys, but it feels as if there is a force dragging it back. When I release the keys it rolls back in to the corner.
     
  10. Lampshade_G

    Lampshade_G

    Joined:
    Jul 3, 2017
    Posts:
    1
    I decided to import a coin.fbx model made from Blender to use for my Pickups. But when editing the collecting the pickups script, I had to add a separate sphere collider component for the coins. How can I import the default colliders for my model?
     
  11. KiShorKumar

    KiShorKumar

    Joined:
    Jul 3, 2017
    Posts:
    1
    I have completed the roll a ball project and i want to build it for android. when i try to build it , it asks me to locate the android sdk folder. what do I do?
     
  12. kajes

    kajes

    Joined:
    Jun 25, 2017
    Posts:
    6
  13. jhlipton

    jhlipton

    Joined:
    Jul 4, 2017
    Posts:
    2
    Thanks for the wonderful tutorial! I was able to build the game in under a day.

    I added a few "bells and whistles" of my own:
    1. Exit button
    2. Speed slider
    3. Yellow Pickup cubes -- set "inactive"; add 1 point
    4. Black "Knockdown" cubes -- keep "active"; subtract 1 point (you can gt a negative score!)
    5. After all Pickup cubes have been collected:
      1. Display "You Win!" in yellow if score is > 4
      2. Otherwise, display "You Lose!" in black
      3. Stop the ball at 0,.0.,0
    On to the next game!
     

    Attached Files:

    • lose.png
      lose.png
      File size:
      146.3 KB
      Views:
      873
    • start.png
      start.png
      File size:
      181.2 KB
      Views:
      805
    • win.png
      win.png
      File size:
      153.5 KB
      Views:
      797
  14. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    144
    Nice job j, adding your own enhancements is a great way to increase your understanding of ATU (All Things Unity) and the ones you've added are really pretty nice. Space Shooter is a good one to personalize as well.

    I too have been pretty pleased and impressed by the tuts these folks provide.
     
    internationalfish likes this.
  15. jhlipton

    jhlipton

    Joined:
    Jul 4, 2017
    Posts:
    2
    Now I want to share with my friends. I have a Facebook build and an Android build; what do I do with them? For Android, I need to create an .apk, right?

    I'm looking into Facebook, but a tutorial would be helpful!
     
  16. ShyamPanchal

    ShyamPanchal

    Joined:
    Jul 6, 2017
    Posts:
    1
    [Help] I am using Unity 5, and i have followed the instructions as said. The game runs as expected in Unity in the Game tab. When i build the game for Windows PC, the game runs but the ball and the cubes do not collide and the ball runs through the code. Where did I go wrong ?
     
  17. TashDash

    TashDash

    Joined:
    Jul 11, 2017
    Posts:
    1
    The game runs fine in Unity but when I build it for Windows and run it, none of the objects have shadows.
     
  18. angel_luis

    angel_luis

    Joined:
    Jun 26, 2016
    Posts:
    17
    Hi,

    I don't understand how deltaTime works...

    "The time in seconds it took to complete the last frame".

    So if the last frame took 0,015 seconds, why we multiply that by a vector3 transfom.Rotation?

    I understand the purpose, rotate the Pick up once per second, instead of per frame. But I don't understand how really it works...
     
    Last edited: Jul 11, 2017
  19. angel_luis

    angel_luis

    Joined:
    Jun 26, 2016
    Posts:
    17
    I have too other question...

    Why we deactivate the Pick Ups instead of Destroy them?
     
  20. FNunesJR

    FNunesJR

    Joined:
    Jul 14, 2017
    Posts:
    2
    Hi there.

    Just finished the "Roll A Ball" tutorial.
    When I enter the Play Mode inside Unity, the game is doing exactly what it should, but when I build it and try to play the .exe, the ball simply goes through the Pick Up cubes

    Any help to solve this?
     
  21. FNunesJR

    FNunesJR

    Joined:
    Jul 14, 2017
    Posts:
    2
    Solved it!

    Spent some time the collectibles tutorial and the cubes all again, but couldn't fix it. After like one hour looking at all messages found this \/ on page5 of the thread.

    Them I deleted the tag, re-opened the project, and with the Tag List empty, created the "Pick Up" tag again and it worked.

    Now I will try another tutorial.
     
  22. VIKTORXDAILY

    VIKTORXDAILY

    Joined:
    Jul 16, 2017
    Posts:
    3
    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 Strat ()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12.     }
    13.  
    14.     private 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.  
     
  23. VIKTORXDAILY

    VIKTORXDAILY

    Joined:
    Jul 16, 2017
    Posts:
    3
    here is my script -- my ball cannot roll and I don't know why, I have been trying to read all reply buti still stuck in this episode please help.. and after I save my script and clicked play button it show NullReferenceExceptiom: Object reference not sent to an instance of an object
     
  24. VIKTORXDAILY

    VIKTORXDAILY

    Joined:
    Jul 16, 2017
    Posts:
    3
    omgggggg solved!!! I don't know why, but I rewrite the script and now it's work!!!
     
  25. angel_luis

    angel_luis

    Joined:
    Jun 26, 2016
    Posts:
    17
    It's void Start (), not void Strat (). ;)
     
    internationalfish likes this.
  26. TheWyrmLord

    TheWyrmLord

    Joined:
    Jul 16, 2017
    Posts:
    2
    Game works until I build and run on pc, at that point the ball goes through the cubes without deactivating them or adding to the score. I've checked to make sure pickup is the tag in my prefabs, and I'm at a loss for ideas.
    Thanks for any advice!


    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.UI;
    6.  
    7. public class PlayerController : MonoBehaviour {
    8.  
    9.     public float speed;
    10.     public Text CountText;
    11.     public Text winText;
    12.  
    13.     private Rigidbody rb;
    14.     private int count;
    15.  
    16.     void Start()
    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*speed);
    31.  
    32.             }
    33.  
    34.     void OnTriggerEnter(Collider other)
    35.     {
    36.         if (other.gameObject.CompareTag("Pickup"))
    37.         {
    38.             other.gameObject.SetActive(false);
    39.             count = count + 1;
    40.             SetCountText();
    41.  
    42.  
    43.         }
    44.     }
    45.     void SetCountText ()
    46.     {
    47.         CountText.text = "Count: " + count.ToString();
    48.         if (count >=12)
    49.         {
    50.             winText.text = "You Win!";
    51.         }
    52.     }
    53. }
    [code tags added - mod]
     
    Last edited by a moderator: Sep 11, 2017
  27. TheWyrmLord

    TheWyrmLord

    Joined:
    Jul 16, 2017
    Posts:
    2
    In the end it fixed itself by closing and reopening Unity. I feel kinda dumb for not trying that first.
     
  28. bananabrett

    bananabrett

    Joined:
    Jul 23, 2017
    Posts:
    1
    Hey, I ran into a problem at the very start of the tutorial. I followed the instructions and went to save the game into the Assets folder, but it keeps on popping up saying that it needs to be saved in the assets folder when that was where I was trying to save it to. What should I do?
     
  29. farzinkhamushi1

    farzinkhamushi1

    Joined:
    Jul 24, 2017
    Posts:
    1
    hi
    I downloaded , watched and did tutorial 1 on you tube (got the link from here) but i had three problem
    1.I had windows10 and may be lot's of people did.
    2.It's exact c# didn't do what the video did
    3.How people can control the game for example hitting the ball to the right or left or something?
    please help me !
     
    Last edited: Jul 27, 2017
  30. Daaaarkness2017

    Daaaarkness2017

    Joined:
    Jul 25, 2017
    Posts:
    2
    Hello, I have a question about cache.
    In the 3-3 Collecting the Pick Up Objects, the narrator says that Unity will recalculate the volumes of static colliders and hold it in a cache only once. But the rotations make Unity recalculate every frame. So the narrator says that we can add the "Rigidbody" component to the pick up(yellow cubes), but won't Unity calculate all objects with rigidbody every frame? I think it shouldnt have any benefit on the optimisation?
     
  31. merrestar

    merrestar

    Joined:
    Jul 31, 2017
    Posts:
    1
    I am in the player movement part of the tutorial. I copied the code but when I play, the ball moves in the opposite direction of the keys I am pressing.
     
  32. Daaaarkness2017

    Daaaarkness2017

    Joined:
    Jul 25, 2017
    Posts:
    2
    May you copy your code here?
     
  33. CParis212

    CParis212

    Joined:
    Aug 2, 2017
    Posts:
    5
    Okay, I've watched the video. I've started all over three times. And I keep getting an error with my compiler. Everything is set up correctly just like the video why does it say, " All Compiler errors have to be fixed before you can enter play mode."
     
  34. CarbuncleOrigin

    CarbuncleOrigin

    Joined:
    Aug 2, 2017
    Posts:
    1
    Hi guys. I'm actually done with the tutorials. It's just that there's this white line that appears on the screen when I create text. Is it normal? If so, then why is there no white line in the tutorials? Hoping for someone's answer. :D
    And another thing that I've noticed, the plane color isn't the same with the one in the tutorial. It seems to have a mixed of color close to red. What makes this happen?
     

    Attached Files:

  35. CParis212

    CParis212

    Joined:
    Aug 2, 2017
    Posts:
    5
    I fixed that problem! now when i load my game in the playable game platform i cannot grab my cubes:(
     
  36. Lucarn

    Lucarn

    Joined:
    Aug 8, 2017
    Posts:
    2
    it says i need the Mono Develop Download to continue with the player controls. is it safe to download?
    upload_2017-8-8_10-7-42.png
     
  37. Faeryia

    Faeryia

    Joined:
    Jul 29, 2017
    Posts:
    5
    Hello everyone! I've managed to go through the roll a ball tutorial and on my second try I got it all working. :D Now I would like to add to it. How do I add a sound-effect so that the game goes "Ping" when I collect one of the spinning cubes? I know I have to import sound as an asset and I suspect I have to use triggers to make it work, but how do I do that, and how do I script it?

    Also, is there a way to make the collectable items stick to the surface of the ball like in the game Katamari? Any help is greatly appreciated.
     
  38. Faeryia

    Faeryia

    Joined:
    Jul 29, 2017
    Posts:
    5
    Hey there. If you don't already know, MonoDevelop is the script-editor used by the Unity Software. On the Mac it seems it is included into Unity, but when I used Unity on the PC and opened a script-file to edit, Visual Basic opened instead, and it worked fine. I think you can basically use any script-editor you want, as for MonoDevelop, if you are downloading from an official Unity-site, I think it is safe to download.
     
    Lucarn likes this.
  39. ro_zorrro

    ro_zorrro

    Joined:
    Aug 9, 2017
    Posts:
    1
    My cubes are not moving the way his cubs. My cubes are going beneath the plan even if it is set to pivot and global. Suggest me solution please.
     
  40. Lucarn

    Lucarn

    Joined:
    Aug 8, 2017
    Posts:
    2
    um i downloaded all 3 of these from the link unity told me to use and it wont work. the error message shows up. and i dunno what to do.

    NVM i just used visual studios instead
     

    Attached Files:

    • ugh.png
      ugh.png
      File size:
      22.5 KB
      Views:
      792
    Last edited: Aug 10, 2017
  41. Faeryia

    Faeryia

    Joined:
    Jul 29, 2017
    Posts:
    5
    You could check your code against the transcript below the vid. If you've made a typo or error you should be able to spot it and correct it.
     
  42. Karis_1

    Karis_1

    Joined:
    Aug 13, 2017
    Posts:
    1
    So I had to open the manual manually because I don't have the ' key on my keyboard. He only mentioned how to open the manual on an American keyborad, but that isn't any use for me when using a German keyboard...
     
  43. Yiffparty_exe

    Yiffparty_exe

    Joined:
    Aug 14, 2017
    Posts:
    3
    So I've literally started learning this today but I can't get past the first scripting. I've restarted it 3 times, and quoted everything letter for letter when naming, but I still get a Compile error. My code is written exactly like the tutorial but I'll post it anyway

    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. }
     
  44. panoskal

    panoskal

    Joined:
    Mar 31, 2017
    Posts:
    28
  45. Yiffparty_exe

    Yiffparty_exe

    Joined:
    Aug 14, 2017
    Posts:
    3
    @panoskal
    "All Compiler errors have to be fixed before you can enter play mode!"
     
  46. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    firstly welcome aboard @Yiffparty_exe :)
    the console window is where you will see all the errors you will generally see.
    if you cant see the console window you can go to Window > Console.

    if you could open the console window, click on the red error you see, it will show a little more information about it, possibly even post the screenshot here please.
     
  47. Yiffparty_exe

    Yiffparty_exe

    Joined:
    Aug 14, 2017
    Posts:
    3
    That would've made a lot more sense.
    The error says;
    * Assertion: should not be reached at ..\mono\utils\mono-dl-windows.c:152
    but I'll include a cap too
    screencap1.png
     
  48. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    eek, no idea what that one is.

    does it happen in a completely fresh project, say if you create a new project, and add a couple of the primitives and try playing?

    i would possibly raise a bug report, i dont have version 2017 myself. i did try a quick search around, but sorry I cant find anything standing out to me.

    info for raising a bug.
    https://unity3d.com/unity/qa/bug-reporting
     
  49. Cookieg82

    Cookieg82

    Joined:
    Mar 28, 2017
    Posts:
    73
    That looks like the canvas when in Scene mode? Goto- > Window -> add a Game window. Run the game. Lines will not show in game view.
     
  50. Cookieg82

    Cookieg82

    Joined:
    Mar 28, 2017
    Posts:
    73
    Check the configuration setting in Build Settings / Player Settings and that it is set on the latest .NET build.
     

    Attached Files: