Search Unity

Roll-a-ball question

Discussion in 'Getting Started' started by ethancodes, Mar 11, 2015.

  1. ethancodes

    ethancodes

    Joined:
    Mar 9, 2015
    Posts:
    30
    I am working through the roll a ball tutorial and am having issues with the camera. I just wrote the script for the main camera and assigned the player game object to it, but the camera is not moving with the player. It just stays still. The only difference I can find in the video is that there is a check mark by the script at the bottom of the inspector, on mine it is not giving me an option to check mark it. any ideas?
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Do you have the method names capitalised properly in your script? update will not work, Update will.
     
  3. blipchik

    blipchik

    Joined:
    Jul 5, 2014
    Posts:
    7
    I was just curious, Is the roll a ball tutorial valid for the Unity 5.0 version? I am also having trouble. I have followed the code instructions and the ball refuses to move still.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    There are two key broken points in Roll-A-Ball.

    The first one from 4.6 is the use of the obsolete GUIText. Updaterd video here.

    www.youtube.com/watch?v=IViD5G2ucNs

    The second from 5.0 is the outdated API. Instead of rigidbody.xxx you must now use GetComponent<RigidBody>().xxx
     
  5. blipchik

    blipchik

    Joined:
    Jul 5, 2014
    Posts:
    7
    Thanks for your response. Unity seems to have autocorrected the code itself with the GetComponent yet it still does not play. Any ideas?
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Can you share your code? Use the code tag button to make it readable.
     
  7. blipchik

    blipchik

    Joined:
    Jul 5, 2014
    Posts:
    7
    this is the code now.

    usingUnityEngine;
    usingSystem.Collections;

    publicclassPlayercontroler : MonoBehaviour
    {

    publicfloatspeed;


    voidFixedupdate ()
    {
    floatmoveHorizontal = Input.GetAxis("Horizontal");
    floatmoveVertical = Input.GetAxis("Vertical");

    Vector3movement = newVector3(moveHorizontal, 0.0f, moveVertical);

    GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);

    }

    }
     
  8. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Fixedupdate should be FixedUpdate.
     
  9. blipchik

    blipchik

    Joined:
    Jul 5, 2014
    Posts:
    7
    Like this?
     

    Attached Files:

  10. blipchik

    blipchik

    Joined:
    Jul 5, 2014
    Posts:
    7
    Hmm ok thank you! Let me try now.
     
  11. ethancodes

    ethancodes

    Joined:
    Mar 9, 2015
    Posts:
    30
    Well that worked but now it looks like my camera is looking out from the ball. I'm not sure why...
     
  12. blipchik

    blipchik

    Joined:
    Jul 5, 2014
    Posts:
    7
    No. This made no difference. Any other thoughts?
     
  13. blipchik

    blipchik

    Joined:
    Jul 5, 2014
    Posts:
    7
    Says the reference script on this behavior is missing
     
  14. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    The file name and class name have to match exactly

    You currently have Playercontroler in your script and playercontroler as the file name.
     
  15. jshrek

    jshrek

    Joined:
    Mar 30, 2013
    Posts:
    220
    So upper/lower case is important, as is proper spelling.

    As mentioned above,
    Code (csharp):
    1. void Fixedupdate ()
    needs to be
    Code (csharp):
    1. void FixedUpdate ()
    Also, your class name is
    Code (csharp):
    1. public class Playercontroler
    but is this correct as it should be
    Code (csharp):
    1. public class PlayerController
    and the script name needs to be the same
    Code (csharp):
    1. PlayerController.cs
     
    Kiwasi likes this.
  16. ethancodes

    ethancodes

    Joined:
    Mar 9, 2015
    Posts:
    30
    soooo anyways...back to the original question that I'm still having issues with...lol. My camera is still shows as a first person from the balls perspective, but not rotating with the camera. It stays level while the ball rolls. Here is my code:

    using UnityEngine;
    using System.Collections;
    public class MainCamera_Script : MonoBehaviour
    {
    public GameObject player;
    private Vector3 offset;
    void start()
    {
    offset = transform.position;
    }
    void LateUpdate()
    {
    transform.position= player.transform.position + offset;
    }
    }

    And everything on the Inspector matches what is shown in the video.
     
  17. jshrek

    jshrek

    Joined:
    Mar 30, 2013
    Posts:
    220
    In the inspector for the camera, did you change the Transform and move it back and up so it starts in the proper position that you want it too?
     
  18. ethancodes

    ethancodes

    Joined:
    Mar 9, 2015
    Posts:
    30
    yes I did. I think what is happening is its reading the offset as 0. because when I press play the main camera moves to the same location as the ball and then moves with it but remains forward facing. Is there a way to set the offset that I am missing?
     
  19. amandaterasu

    amandaterasu

    Joined:
    Mar 13, 2015
    Posts:
    2
    Last edited: Mar 13, 2015
  20. jshrek

    jshrek

    Joined:
    Mar 30, 2013
    Posts:
    220
    @GetOverHere89

    Yes you have the exact same problem ...

    void start() should be void Start()

    You need upper case S on start.
     
  21. ethancodes

    ethancodes

    Joined:
    Mar 9, 2015
    Posts:
    30
    AHA! Jeez I can't believe I missed that! Something so small! Thank you so much!
     
  22. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    I was having similar issues where it looked like the ball was floating in midair then after about 30 seconds it would drop through the floor. Turns out it was the game camera angle playing optical illusion on me. Once I changed the angle of camera I could see that the ball was always moving and when it fell through, it actually just hit the edge of the plain. Felt very foolish about this.
     
  23. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    I am having a different issue now. I am working on the collecting part of the tutorial and I had it to the point where I could go through the cubes, but without the collider portion. But now I can't get the game to run due to CS1061 error:

    " Assets/_Script/playerctrl.cs(23,31): error CS1061: Type `UnityEngine.Collider' does not contain a definition for `gameobject' and no extension method `gameobject' of type `UnityEngine.Collider' could be found (are you missing a using directive or an assembly reference?) "

    I'm not sure as to what I changed to cause this error to happen. I do have my prefab made and tag set at "PickUp", Box Collider is on; Added the Rigidbody and clicked on Is Kinematic as well.

    Here is my code:

    using UnityEngine;
    using System.Collections;
    public class playerctrl : MonoBehaviour
    {
    public float speed;
    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis ("Horizontal");
    float moveVertical = Input.GetAxis ("Vertical");
    Vector3 movement = new Vector3(moveHorizontal, 0, moveVertical);
    GetComponent<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
    }
    // Destroy everything that enters the trigger

    void OnTriggerEnter(Collider other)
    {
    if (other.gameObject.tag == "PickUp")

    {
    other.gameobject.SetActive(false);
    }
    }
    }
     
  24. Effervescent

    Effervescent

    Joined:
    Mar 7, 2015
    Posts:
    31
    If I'm not mistaken, it's most likely because you typed gameobject instead of gameObject in Line 23. Try this:

    Code (csharp):
    1. void OnTriggerEnter(Collider other) {
    2.      if (other.gameObject.tag == "PickUp") {
    3.           other.gameObject.SetActive(false);
    4.      }
    5. }
    For future reference, you can format codes with the code tags [code ] and [/ code] (without the space); it would make things easier for others to read particularly if you are quoting the line number(s) shown in the debugger!

    Feeling silly is part of learning - I still do amazingly silly things after a few weeks and probably won't stop doing that for a while. xD
     
  25. Jeriko2k3

    Jeriko2k3

    Joined:
    Mar 18, 2015
    Posts:
    28
    just got home and made the fix. Perfect. Capital letters arghh. Thanks!