Search Unity

  1. We've closed the job boards. If you're looking for work, or looking to hire check out Unity Connect. You can see more information here.
    Dismiss Notice
  2. Unity 2017.3 has arrived! Read about it here.
    Dismiss Notice
  3. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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
    Is it either outdated our am I doing it wrong?
     
  2. Lamb7

    Lamb7

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

    Lamb7

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

    Lamb7

    Joined:
    Jun 26, 2017
    Posts:
    5
    How do i fix it.....
     
  5. 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.
     
  6. 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
     
  7. 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
     
  8. 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?
     
  9. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    834
    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.
     
  10. 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.
     
  11. SpartanIM99

    SpartanIM99

    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?
     
  12. 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?
     
  13. kajes

    kajes

    Joined:
    Jun 25, 2017
    Posts:
    6
  14. 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:

  15. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    124
    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.
  16. 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!
     
  17. 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 ?
     
  18. 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.
     
  19. angel_luis

    angel_luis

    Joined:
    Jun 26, 2016
    Posts:
    7
    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
  20. angel_luis

    angel_luis

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

    Why we deactivate the Pick Ups instead of Destroy them?
     
  21. 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?
     
  22. 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.
     
  23. 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.  
     
  24. 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
     
  25. 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!!!
     
  26. angel_luis

    angel_luis

    Joined:
    Jun 26, 2016
    Posts:
    7
    It's void Start (), not void Strat (). ;)
     
    internationalfish likes this.
  27. 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
  28. 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.
     
  29. 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?
     
  30. 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
  31. 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?
     
  32. 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.
     
  33. Daaaarkness2017

    Daaaarkness2017

    Joined:
    Jul 25, 2017
    Posts:
    2
    May you copy your code here?
     
  34. 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."
     
  35. 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:

  36. 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:(
     
  37. 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
     
  38. 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.
     
  39. 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.
  40. 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.
     
  41. 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:
      16
    Last edited: Aug 10, 2017
  42. 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.
     
  43. 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...
     
  44. 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. }
     
  45. panoskal

    panoskal

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

    Yiffparty_exe

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

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    834
    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.
     
  48. 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
     
  49. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    834
    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
     
  50. Cookieg82

    Cookieg82

    Joined:
    Mar 28, 2017
    Posts:
    42
    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.