Search Unity

Official Roll-a-ball Tutorial Q&A

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

  1. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Code looks ok s1mpleduck.

    Do they just "disappear", or fall through the floor. It sounds like you may have an issue with a setting somewhere , which is more difficult to diagnose through the forums. Try checking a couple things,

    Make sure the sphere collider is scaled to match the player sphere,
    Make sure that convex is not selected on your floor plane,
    make sure isKinematic is selected on your pick up cubes,
    make sure you didn't add the collision scripting to your pick ups.

    I have one other suggestion, but want to test it first.
     
  2. s1mpleduck

    s1mpleduck

    Joined:
    Feb 4, 2017
    Posts:
    6
    They just disappear when i press play, I just checked the other things and they still disappear
     
    Last edited: Feb 4, 2017
  3. s1mpleduck

    s1mpleduck

    Joined:
    Feb 4, 2017
    Posts:
    6
  4. Deleted User

    Deleted User

    Guest

    Did you click on the link I put in my post? It tells you how to do that.
     
  5. s1mpleduck

    s1mpleduck

    Joined:
    Feb 4, 2017
    Posts:
    6
    I did but im very confused
     
  6. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    s1mpleduck,

    It seems confusing at first but it is not difficult once you do it. In your editing program highlight your code and press CTRL + C to copy it.

    In your forum post there is a bunch of little icons across the bar at the top. Towards the right side, if you mouse over you will see one that says "insert" (looks like a menu). If you click on that it will bring up a window. You can click in the window then hit CTRL + V to paste your code.
     
  7. s1mpleduck

    s1mpleduck

    Joined:
    Feb 4, 2017
    Posts:
    6
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class playercontrol : MonoBehaviour
    4. {
    5.     public float speed;
    6.     private Rigidbody rb;
    7.     void Start()
    8.     {
    9.         rb = GetComponent<Rigidbody>();
    10.     }
    11.     void FixedUpdate()
    12.     {
    13.         float moveHorizontal = Input.GetAxis("Horizontal");
    14.         float moveVertical = Input.GetAxis("Vertical");
    15.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    16.         rb.AddForce(movement * speed);
    17.     }
    18.     void OnTriggerEnter(Collider other)
    19.     {
    20.         if (other.gameObject.CompareTag("Pick Up"))
    21.         {
    22.             other.gameObject.SetActive(false);
    23.         }
    24.     }
    25.  
     
  8. ecmr

    ecmr

    Joined:
    Feb 5, 2017
    Posts:
    2
    I've finished the tutorial and it's great. However, I had to remove the text because it was too big to fit on the screen. On the tutorial it seemed small but it took me over 30 seconds to zoom out to see the text! Any ideas on why Unity would do this?
     
  9. Deleted User

    Deleted User

    Guest

    Tou probably entered a wrong size for the text. Or you ticked the "best fit" box.
     
  10. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    BramSter,

    It sounds like you may confusing the text as seen on the game tab, v.s. as seen on the scene tab. Don't worry too much about how it looks in the scene tab, as long as it is correct in the game.
     
  11. paolo_t

    paolo_t

    Joined:
    Feb 7, 2017
    Posts:
    1
    Hi.

    I want to play the game on my android phone. I selected android in the build setting window but I don't know how to put it in my phone. (I have my phone connected to my laptop).
     
  12. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    You may get better responses if you post this in the Android Forum.
     
  13. Joost26

    Joost26

    Joined:
    Feb 8, 2017
    Posts:
    2
    Can somebody help me? I made it to the end of the tut and in the game view everything works just fine. But when I build up my game, and want to play it outside the editor, this is the only thing i see. the score i got, but not the rest of the game. and it doenst matter in what resolution i run it.

    upload_2017-2-8_15-59-50.png
     
  14. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Joost26,

    Make sure in your build setting that you have the correct platform selected. It's possible to have the correct platform highlighted, but not selected. It needs to have the Unity symbol to the right of the platform. Double check build settings and try again and see if that makes a difference.
     
  15. kprsnt

    kprsnt

    Joined:
    Feb 8, 2017
    Posts:
    1
    hiii even im facing the same problem i checked everything but its not working and i got one warning that
    There are inconsistent line endings in the 'someFileName.cs' script. Some are Mac OS X (UNIX) and some are Windows.
    This might lead to incorrect line numbers in stacktraces and compiler errors. Unitron and other text editors can fix this using Convert Line Endings menu commands what can i do now please help me out
     
  16. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    kprsnt,

    The inconsistent line endings should have no effect on the way the program runs. It may cause it to be a little harder to debug by line numbers is all. Here is a good post explaining it.
    https://forum.unity3d.com/threads/inconsistent-line-spacing.454164/

    If you could explain what is not working and post any relevant code you have someone here may be able to help you. Be sure to use code tags as it makes it much easier for others to read your code. Post #1207 in this thread gives a quick how to if you're not sure.
     
  17. Deleted User

    Deleted User

    Guest

    Did you both add the scene when you built your games?

    https://docs.unity3d.com/Manual/BuildSettings.html
     
  18. mrstefanic

    mrstefanic

    Joined:
    Dec 4, 2016
    Posts:
    2
    Hello, Is there a video that shows how to make it playable with android? That would be great
     
  19. BruceCarroll

    BruceCarroll

    Joined:
    Feb 11, 2017
    Posts:
    1
    This is all very frustrating for a beginner. Is there a "Unity for Dummies?" Are there any tutorials in, say, a PDF, so I don't have to keep scrolling back the video? Are there any tutors available? I need something that starts with "This is the letter "A," or whatever the game designer/programmer equivalent is.
     
  20. Smit95

    Smit95

    Joined:
    Feb 11, 2017
    Posts:
    1

    Hey,
    Nice tutorial on Roll-a-ball. I would like to know how can i add a objects through the c# code.

    I tried the below code in players component but it doesnt seem to work!

    void Update()
    {
    var gameObject = new GameObject("PickUp");
    gameObject.tag = "PickUp";
    gameObject.SetActive (true);
    var meshFilter = gameObject.AddComponent<MeshFilter>();
    gameObject.AddComponent<MeshRenderer>();
    meshFilter.sharedMesh = objectToCreate;
    Vector3 movement = new Vector3 (transform.position.x-2f, 0.5f, transform.position.z-5f);
    gameObject.transform.position = movement;

    gameObject.transform.rotation = transform.rotation;
    }
     
  21. Deleted User

    Deleted User

    Guest

    Your code is incomprehensible, use the code tags so that it becomes more readable: http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  22. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Smit95,

    As AnneSchmidt mentioned, code tags make the code much easier to interpret and are easy to use.

    I see you want to use C# to add the objects, but your sample code looks like JavaScript (UnityScript). Typically the easiest way to add objects is by instantiating your prefab. Here is the scripting API for it
    https://docs.unity3d.com/ScriptReference/Object.Instantiate.html
    though there are quite a few options, I think the most common use is

    Instantiate(object, vector3 position, vector3 rotation);
     
  23. Joost26

    Joost26

    Joined:
    Feb 8, 2017
    Posts:
    2
    Hi Anne,

    Yes i added the scene and used the correct platform with the unity logo on it!

    maybe there is something wrong with the settings?
     

    Attached Files:

    • Q&A1.png
      Q&A1.png
      File size:
      295.5 KB
      Views:
      733
  24. PaToNi

    PaToNi

    Joined:
    Feb 26, 2017
    Posts:
    1
    Hello everyone, this is a great project for learning Unity. It is the very first time i worked with it and after finishing this tutorial I feel like I learned a lot. I do however have a big question mark, about the UI. Specifically the canvas and text overlay, in the tutorial you don't even see the canvas and everything looks smooth and easy, well when i created the text it looked all weird and the canvas was huge. Can someone please explain me why is that?
    upload_2017-2-26_16-55-11.png
     
  25. Bobonevive96

    Bobonevive96

    Joined:
    Feb 26, 2017
    Posts:
    6
    HI there, i've been watching this tutorial but I can't go over the secondo point since, whatever i do, my ball doesn't want to move. This is the code that i've written
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class move : MonoBehaviour {
    6.  
    7.     public Rigidbody playerRigidBody;  
    8.     public float speed;
    9.  
    10.  
    11.     void Start () {
    12.        
    13.         playerRigidBody = GetComponent<Rigidbody> ();
    14.         if (playerRigidBody != null)
    15.         {
    16.             Debug.Log ("Success! We have a Rigidbody reference!");
    17.         }
    18.         else
    19.         {
    20.             Debug.Log ("Failure! We do not have a Rigidbody reference!");
    21.         }
    22.     }
    23.    
    24.     void fixedUpdate () {
    25.        
    26.         float moveHorizontal = Input.GetAxis ("Horizontal");
    27.         float moveVertical = Input.GetAxis ("Vertical");
    28.  
    29.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    30.  
    31.         playerRigidBody.AddForce(movement * speed);
    32.  
    33.     }
    34. }
    35.  
    In addition here's a screen of my unity ui
    roll.png
    ps what instance id and local identifier do?? thanks in advance
     
  26. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Bobonevive96,

    Line 24 should be FixedUpdate, with capital F.

    I believe instance ID and identifier are ways to identify that particular component, but not sure.
     
  27. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    PaToNi,

    If you are referring to the way the canvas looks in the scene view, I think it is pretty normal to look strange there. As long as it looks ok in the game, I think you will be fine.
     
  28. Bobonevive96

    Bobonevive96

    Joined:
    Feb 26, 2017
    Posts:
    6
    thanks, but it still doesn't work
     
  29. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Other than the lowercase f in your FixedUpdate method the code looks good.

    A common issue is forgetting to set the speed value in the inspector, but I see in your picture you have it set to 100.

    I would check the input manager and make sure the input is set up for the keys you are using.
     
  30. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Just noticed on your Rigidbody you have isKinematic selected. You want that to be unselected so physics forces will apply. That should fix it for you.
    edit> also select use gravity
     
  31. Bobonevive96

    Bobonevive96

    Joined:
    Feb 26, 2017
    Posts:
    6
    still nothing neither with arrows nor asdw

    [EDIT]: I've also checked the imput manager and i've stetted arrows as imput and asdw as alternative imput
     
    Last edited: Feb 27, 2017
  32. ABDULLAHGULZAR

    ABDULLAHGULZAR

    Joined:
    Feb 27, 2017
    Posts:
    1
    can you tell me how to fix compile errors
    :(
     
  33. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    ABDULLAHGULZAR, Compile errors typically mean something is wrong with your code. Could be something simple as missing a curly brace, or something spelled incorrectly. Try posting your code here and someone may be able to locate the issue. Or if you could post an error message.

    Bobonevive96, your issue is vexing me and is probably outside of my limited knowledge. How did you get the Identifiers and instance name fields to show up in your inspector. I don't get that in my inspector, maybe that has something to do with it. I doubt it, but....
     
  34. Bobonevive96

    Bobonevive96

    Joined:
    Feb 26, 2017
    Posts:
    6
    Ryeath (i don't know how to tag), i'm an absolute beginner in unity and i still don't understand everything (i understand only very little tbh). at the beginning I had my inspector on normal and i had my script greyed and I read on another forum that i need to have my inspector on debug and as soon as i switched it to debug they've showned up, i don't know how i don't know why
     
  35. brodan100105

    brodan100105

    Joined:
    Jul 16, 2016
    Posts:
    13
    So, tutorial was great first off, but i have a question, say i wanted to connect my game to another level, like i collect all the "points" and you win. but how do you change levels after you win? could someone tell me how?
     
  36. GameJob2017

    GameJob2017

    Joined:
    Mar 1, 2017
    Posts:
    18
    I am using the latest Unity (version 5.5.2f1) and latest XCode (8.2.1) as of Feb 2017.

    My Unity sample project "Roll a Ball" works perfectly well on my Mac. But, when I build and deploy it on my iPad, and play it, I notice that the ball does not roll or move at all, which is the problem here. (But, all the cubes are rotating just fine on iPad).

    Does anyone have any idea on how to fix this ?

    Thanks.
     
  37. Blodis

    Blodis

    Joined:
    Apr 2, 2013
    Posts:
    4
    So I've done the whole first tutorial now, the ball game. I built it and ran it. Everything works except collecting the collectables. I just go through them and there's no collision. Any ideas? I've even copied the scripts from the tutorial (wrote by hand to get it in to my fingers first).

    It works perfectly like it should in game mode in Unity, just not in the executable file.
     
    Last edited: Mar 8, 2017
  38. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Came accross this a while ago as well, try resetting/reselecting the tags on the collectables and the player. think they go a bit funny when built sometimes (not very often tho)
     
  39. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    how are you controlling it on the Ipad?
    Im guessing that the Mac you are using the keys, but the mobile device would use the accelerometer i assume?
     
  40. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    afternoon,
    you will have to use the new scenemanager to load another scene
    https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

    look at the build index in File > BuildSettings to get a list of scenes and their values.

    also remember to include the UnityEngine.SceneManagement; namespace at the top as shown in the example script on that page above.
     
  41. Blodis

    Blodis

    Joined:
    Apr 2, 2013
    Posts:
    4

    Sadly it doesn't seem to work =/ Thanks anyway.

    Al the collectables in the hierarchy are blue while every other thing is black. I wonder if that has anything to do with it.
     
  42. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    the blue tint in the names means they are prefabs.
    Just out of curiosity is the current scene the one that you have in your Build Settings just in case your working on a different one that whats getting built?
    File > BuildSettings
     
  43. Blodis

    Blodis

    Joined:
    Apr 2, 2013
    Posts:
    4
    Hey, it worked out with your tip afterall. Turned out I only reselected and thoguht that might do it. And when my brain started working again I managed to reset the tag and because I had the script open I needed to write in the exact same tag again it seemed. Anyway, it works now. Thank you so much :)
     
  44. PaulGreninger

    PaulGreninger

    Joined:
    Feb 27, 2017
    Posts:
    7
    I'm having trouble with Roll a Ball (3), Moving the camera. In the hierarchy view, I place the camera into the Player folder (child of the player), and then hit the play button. Using the a and d keys, the whole plane and ball rotates, where as before it did not rotate. It just moved the ball.
     

    Attached Files:

  45. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    Paul,

    The camera should not be a child of the player sphere. It should be it's own independent object that uses an offset from the player sphere transform.
     
  46. imthemonster

    imthemonster

    Joined:
    Mar 4, 2017
    Posts:
    7
    I followed the part 01 of tutorial, and the ball is in position 0, 0,5, 0, on the ground, like this: upload_2017-3-8_20-52-4.png

    But when i hit play, the ball goes up and if i hit keys, the ball moves off the plan

    upload_2017-3-8_20-52-57.png
     

    Attached Files:

  47. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    imthemonster,

    check your plane (ground object) and look at the collider on it. Make sure it is a mesh collider, not a box collider. It is behaving like your ground has a box collider and the sphere is inside of it. When that happens the first thing the game does when it starts is to kick the sphere out of the box.

    If that doesn't do it then make sure you reset the transform of the sphere and if you have the sphere as a child of anything that should be reset also.
     
    OboShape likes this.
  48. ZeRuc

    ZeRuc

    Joined:
    Mar 3, 2017
    Posts:
    25
    I have added the skybox to the scene, but since the camera is oriented in a way that the player won't ever see it, I want to remove it. How do I do that?

    I have also tried to make the pickup cubes (or in my case, coins) move to another point on the XZ plane after I pick them up, but they are also being moved in the Y direction. The relevant code bit goes like this:
    Code (CSharp):
    1.     private void OnTriggerEnter(Collider other)
    2.     {
    3.         if (other.gameObject.CompareTag("Coin"))
    4.         {
    5.             //DestroyObject(other.gameObject);
    6.             Debug.Log(other.gameObject.transform.position.x);
    7.             Debug.Log(other.gameObject.transform.position.y);
    8.             Debug.Log(other.gameObject.transform.position.z);
    9.             other.gameObject.transform.Translate(Random.Range(-10f, 10f) - other.gameObject.transform.position.x, 0f, Random.Range(-10f, 10f) - other.gameObject.transform.position.z);
    10.             Debug.Log(other.gameObject.transform.position.x); //this should be and is a random value between -10 and 10
    11.             Debug.Log(other.gameObject.transform.position.y); //this should stay unchanged but is also is a random value between -10 and 10
    12.             Debug.Log(other.gameObject.transform.position.z); //this should be and is a random value between -10 and 10
    13.         }      
    14.     }
     
  49. Ryeath

    Ryeath

    Joined:
    Dec 4, 2016
    Posts:
    265
    ZeRuc,

    Have you tried using transform.position, instead of transform.translate?

    Translate moves the object in a linear fashion and typically has a distance that it moves each frame, and the movement is relative to the objects local orientation unless global is specified. If your coins are rotating on either the X or Z axis, that could be causing your issue. So if you want it to move immediately to the new location you probably want to use transform.position.

    As for the Y axis changing, I'm not sure, the code looks ok but is a bit hard to read. When I get into a lot calculations I like to do them separately on their own line before putting them into a Vector3.

    https://docs.unity3d.com/ScriptReference/Transform.Translate.html
     
  50. ZeRuc

    ZeRuc

    Joined:
    Mar 3, 2017
    Posts:
    25
    That explains it! I've used a script to make the coins slowly rotate for a better visual effect which obviously changed their orientation. Now I changed the code to:

    Code (CSharp):
    1. other.gameObject.transform.position = new Vector3(Random.Range(-10f, 10f), 0.5f, Random.Range(-10f, 10f));
    and it works like I intended :)