1. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  2. Unity 2017.2 beta is now available for download.
    Dismiss Notice
  3. Unity 2017.1 is now released.
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice
  6. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    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
    Hello its telling me that rb does not exist and I just now got into coding and other things like that so I dont know what to do when it says rb does not exist or anything else does not exist
     
  2. Lamb7

    Lamb7

    Joined:
    Jun 26, 2017
    Posts:
    5
    Is it either outdated our am I doing it wrong?
     
  3. Lamb7

    Lamb7

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

    Lamb7

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

    Lamb7

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

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    831
    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.
     
  11. Bakerfield

    Bakerfield

    Joined:
    Jul 2, 2017
    Posts:
    1
    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.
     
  12. 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?
     
  13. 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?
     
  14. kajes

    kajes

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

    internationalfish likes this.
  16. gwnguy

    gwnguy

    Joined:
    Apr 25, 2017
    Posts:
    63
    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.
  17. 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!
     
  18. 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 ?
     
  19. 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.
     
  20. 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
  21. 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?
     
  22. 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?
     
  23. 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.
     
  24. 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.  
     
  25. 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
     
  26. 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!!!
     
  27. angel_luis

    angel_luis

    Joined:
    Jun 26, 2016
    Posts:
    7
    It's void Start (), not void Strat (). ;)
     
    internationalfish likes this.
  28. 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!



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

    public class PlayerController : MonoBehaviour {

    public float speed;
    public Text CountText;
    public Text winText;

    private Rigidbody rb;
    private int count;

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

    void FixedUpdate()
    {
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

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

    rb.AddForce(movement*speed);

    }

    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.CompareTag("Pickup"))
    {
    other.gameObject.SetActive(false);
    count = count + 1;
    SetCountText();


    }
    }
    void SetCountText ()
    {
    CountText.text = "Count: " + count.ToString();
    if (count >=12)
    {
    winText.text = "You Win!";
    }
    }
    }
     
  29. 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.
     
  30. bananabrett

    bananabrett

    Joined:
    Sunday
    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?
     
  31. farzinkhamushi1

    farzinkhamushi1

    Joined:
    Yesterday
    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?
    I'll thank you if help me more