Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Official Roll-a-ball Tutorial Q&A

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

  1. vmadev

    vmadev

    Joined:
    Dec 16, 2015
    Posts:
    5
    Hi

    I am a newbie here and the Roll A Ball script is not working for the Rigidbody but works well for the scenarios explained below.

    Can anybody explain this phenomenon

    The code is here

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

    public class PlayerController : MonoBehaviour {
    public float speed=10;
    //private CharacterController cc;
    private Rigidbody rb;

    void Start ()
    {
    rb=GetComponent<Rigidbody>();
    // cc = GetComponent<CharacterController>();

    }

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

    Debug.Log("I am alive and H : " + moveHorizontal);

    Debug.Log("I am alive and V : " + moveVertical);


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


    //speed value is set to 10 in the inspector
    rb.AddForce(movement * speed);

    //cc.Move(movement*speed);

    }
    }

    Scenario 1:
    Rigidbody : Doesnt't work

    Scenario 2:
    When I added CharacterController instead and unchecked Rigidbody it works fine but speed is not shown in the CharacterCountroller in inspector for the Player

    Scenario 3
    With rb uncommented and cc commented out and if CharacterController is still selected along with Rigidbody it still works.

    Any help is appreciated
     
  2. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    When you say it doesn't move like mine does , do you mean it moves but you don't like the way it moves or are you saying that it doesn't move at all? If it doesn't move at all then there are some things to look at, like: have you attach the script to the game object? Do you have any value for speed?
     
  3. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I'm sorry to say that I am thoroughly confused. First of all can you please use code tags when posting your code. It makes it far easier to understand. Second, I don't understand your use of the character controller… Why do you have a character controller attached the ball? Lastly I'm not quite sure I understand what you mean by saying "the rigidbody doesn't work"… Can you please use code tags and give us a little more detail?
     
  4. KnightShift

    KnightShift

    Joined:
    Dec 11, 2015
    Posts:
    17
    I wasn't clear, the camera don't follow the ball. I followed all details, script looks like yours, the 2 codes are exact, everything you did, I copied, and it just dont work.

    Seriously though, not to be rude I can't be running around playing 20 questions if that's what's going to happen. If anyone can assist by helping me find out what's actually done to attach camera's to a player/object or direct me to a tutorial that does something similar in a hands-on approach please do so.

    Wasted 2 days so far, thats time (i have loads of free time, no job) i could have spent practicing. about to give up on this tutorial and move on.
     
    Last edited: Dec 18, 2015
  5. DrKel

    DrKel

    Joined:
    Dec 18, 2015
    Posts:
    2
    Hi Adam and thank you for an excellent tut. I am very new to Unity and have just started the first tut roll-a-ball and am a little stuck on the "Moving the camera section" where I cannot find how to create the Player slot within the Camera Controller (Script), could you please let me know what I might have missed? Thank you in anticipation. CamCont.gif
     
  6. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning @DrKel,
    can you double check within your CameraController script that you have declared the player GameObject as public.
    Code (CSharp):
    1. public GameObject player;
    if that doesn't work, try removing and re-adding the script component.
     
  7. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    When asking for help, it's best to be clear, concise and complete. As you can see from my profile, I answer many thousands of questions, and many are similar. the best way to get complete answers is to ask complete questions.

    Remember code is not the only facet to making a game in Unity. It also needs to be instantiated in the scene and the code often needs specific settings. When in doubt double check all of the steps in the video. They do work if followed carefully.

    This sounds like one of the following: The script is written correctly, but not attached to the appropriate GameObject; often this happens when it's not attached at all. This could be that there references to related GameObjects and components are not set correctly - the script is attached, but does not reference the player, etc. There is an error in the console that is preventing the script from compiling: are you getting any errors in the console? The script is written correctly, but has not been saved.

    What more details can you give us? Otherwise we will need to keep asking 20 questions or playing charades until we get the details information we need.

    Don't forget you can link screenshots, code (use code tags, please!), video and attachments. These can all help give the detailed information we need to help you solve your issue.
     
  8. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This could also be related to a compile error? Are there any errors in your console? If the script has not compiled properly (and this can be blocked by an error in another script!), then you won't see the public GameObject player; in the inspector.
     
  9. ess.nasser

    ess.nasser

    Joined:
    Dec 18, 2015
    Posts:
    1
    using UnityEngine;
    using System.Collections;

    public class NewBehaviourScript : MonoBehaviour {

    private Rigidbody rb;

    void start(){

    rb = GetComponent<Rigidbody>();
    }
    void fixedupdate(){
    float movehorizontal = Input.GetAxis ("horizontal");
    float moveVertical = Input.GetAxis ("vertical");
    Vector3 movement = new Vector3 (movehorizontal , 0.0f , moveVertical);
    rb.AddForce(movement);
    }
    }

    This is the code but the ball dosen't move
     
  10. KnightShift

    KnightShift

    Joined:
    Dec 11, 2015
    Posts:
    17
    -uncertain about my situation-
    I got the issue fixed, but then it came back. I think its the cause of this ( http://puu.sh/m0wCD/4d30134233.png ) prompt in Visual studio.
    Im investigating the fix. I think I need a new way to write the C# code.
    I have everything connected properly.

    Final Edit- Got it working. As expected visual studio is making it function odd. In reference to the above picture, if i accepted the request to change the "Line ending" it'd make the code not work.

    Whats the program you and the other users often use for the scripting?
     
    Last edited: Dec 18, 2015
  11. DrKel

    DrKel

    Joined:
    Dec 18, 2015
    Posts:
    2
    THANKS - I removed and re-added the script component, I also moved the 'player.sc' into the scripts folder, all ok, thanks
     
  12. HoodedGaming

    HoodedGaming

    Joined:
    Dec 19, 2015
    Posts:
    2
    How do you set up the input axes. I keep getting errors saying it isn't set up and i simply can't figure it out.
     
    Last edited: Dec 19, 2015
  13. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Please use code tags when posting code.
     
  14. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    C# is case sensitive. Start and FixedUpdate are not spelled correctly.
     
  15. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    We use monodevelop, which is bundled with unity. Unfortunately, I've never seen line endings actually do anything except generate a warning. There could be another underlying issue.
     
  16. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    This is probably due to a typo or misspelling. The default axes are already set up. They need to be spelled exactly as in the video, or unity will assume you are setting up a new and different input axis.
     
  17. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,043
    rollin ... rollin ...rollin .. them ballies keep a rollin
     
    Last edited: Dec 20, 2015
  18. janineteo

    janineteo

    Joined:
    Dec 21, 2015
    Posts:
    2
    Hi all, I faced the same problem as the users above (inuonlyone and IamMurloc) - and was really frustrated. And I realised that even though when you are creating a new project and 3D is selected by default (in Red), you still needed to click on it again, for it to be selected. Without clicking on "3D" again, you will not get the default light. Hope it helps! :)
     
  19. janineteo

    janineteo

    Joined:
    Dec 21, 2015
    Posts:
    2
    Hello all,

    I am new to Unity. I am currently stuck at "Moving the Player". My sphere just wouldn't move. Can you please help look where did I go wrong?

    Thank you! I am on Unity 5.3



    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. }
    [Edited for in-line images - Mod]
     
    Last edited by a moderator: Jan 5, 2016
  20. vmadev

    vmadev

    Joined:
    Dec 16, 2015
    Posts:
    5
    Hi

    I recreated the project and here is the code and the screen shots.

    Let me answer your questions first

    "Why do you have a character controller attached the ball?"

    When the ball was not rotating after attaching the script to the player I was just trying all other controllers and when I attached the ball to a character controller it worked as explained in my previous post. In this new build I have removed the CharacterController.

    "I'm not quite sure I understand what you mean by saying "the rigidbody doesn't work"

    Ball rolled when I unchecked the rigidbody and checked the CharacterController.

    Anyways, now that I have created a fresh project

    Even after creating a fresh project ball is still not rolling.... what I am missing here?

    I have inserted two debug statements to check the values of moveHorizontal and moveVertical. PFA screenshot of the debug console window.. both are zero. I also noticed initially there is some change in the Position X & Y values of the player(screen shot-RAB5-console window)

    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.         Debug.Log("I am alive and H : " + moveHorizontal);
    20.  
    21.         Debug.Log("I am alive and V : " + moveVertical);
    22.      
    23.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    24.  
    25.         rb.AddForce (movement * speed);
    26.     }
    27.  
    28. }

    RAB3.png
    RAB4.png

    Debug info RAB5.png
     
    Last edited: Dec 22, 2015
    kidcoder likes this.
  21. HoodedGaming

    HoodedGaming

    Joined:
    Dec 19, 2015
    Posts:
    2
    Ok i just copied the code and it works now. I guess it was just a spelling error somewhere as i copied the code from the video.
     
  22. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    evening @ibyte, as this thread is related to the roll-a-ball in the tutorials section and unrelated to the 'rollerball' in the standard assets package, maybe a better place to get a response would be within the physics section of the forum where a larger target audience could assist, or possibly raise a bug.

    But, that said, I've had a look for you to see what I could come up with just to help you out in the interim. not my forte, but seemed to work-ish when i was testing tonight.

    Short of reading up on mass-normalised kinetic energy (bit late at night for me)

    you could always open up the Ball.cs script, and pop a larger sleep threshold in the start method, this will set it just for this rigidbody and keep the general physicsManager setting for the threshold of 0.005 for everything else.

    Code (CSharp):
    1.    private void Start()
    2.         {
    3.             m_Rigidbody = GetComponent<Rigidbody>();
    4.             GetComponent<Rigidbody>().maxAngularVelocity = m_MaxAngularVelocity;
    5.  
    6.             // POP THIS LINE IN TO SET THE SLEEP THRESHOLD FOR THE THIS RIGIDBODY //
    7.             m_Rigidbody.sleepThreshold = 0.8f;
    8.         }
    have a go at that, hope that helps in the meantime.
     
  23. Ittoryu

    Ittoryu

    Joined:
    Dec 21, 2015
    Posts:
    2
    Hi!

    I've just finished the tutorial and everything went well (and also a big thank you to Unity for the awesome tutorials!).

    I've got just two questions:

    1)I've posted my original question here: http://answers.unity3d.com/questions/1116193/reload-level-after-timer-hits-0.html I am not sure if I can post it here as well, as it's not strictly related to the tutorial itself (more of an extension). I apologise if this is not the right thread to ask.

    2) Can I also ask a recommendation on what tutorial to follow after? Will it be the space shooter?

    Thanks again!
     
  24. Captain_Piff

    Captain_Piff

    Joined:
    Dec 22, 2015
    Posts:
    1
    Ball doesn't move.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class playerscript : 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. }
    25.  
    script runs without errors. Ball wont move, no matter speed nor direction.
     
  25. GoosePilot

    GoosePilot

    Joined:
    Dec 25, 2015
    Posts:
    1
    Hi, First up- Happy Christmas! This is my first go at unity so bear in mind I that everything is new to me! I have been working through the roll a ball tutorial and have reached the 'Moving the Player' section. I have followed up to the point where you write 'Input', select it, and then bring up the documentation help with Ctrl+'. This is not opening for me for some reason.

    I downloaded Unity 5.3.1f1 yesterday afernoon and did the standard installation. I did some searching online and read about Visual Studio tools for Unity, which didn't seem to be installed on my pc, so I downloaded and installed that, however it hasn't helped my problem. Obviously I can open it separately but this shortcut would be very convenient if I can get it to work.

    Any help you can give me would be much appreciated.
     
  26. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning, a Merry Xmas to you too :)
    Have a read of this post, hope it might shed a little light
    http://forum.unity3d.com/threads/getting-ctrl-to-work-within-vs.372584/
     
  27. Deleted User

    Deleted User

    Guest

    having a problem playing the game, after implementing first code to rigidbody. i think the problem is with camera in game window after i click play. as you can see from image i only see a ball and whole blue background and the same thing is happening after i click play and nothing happens when i run it and try pressing WASD.. Also i didnt have directional light in hierarchy but had to do it manually by looking into other tutorials, do you know why this is?

    Thanks in advance
     

    Attached Files:

  28. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon @Mindim,

    The cameras current position seems to be looking directly side on to the ground plane. so effectively if you imagine looking side on to a really thin sheet of paper side on you will not see it.

    if you look at the moving the camera video, and adjust the camera position & rotation in the inspector according to Adams position and rotation in the video see if that improves what the camera sees in the game view.
    http://unity3d.com/learn/tutorials/projects/roll-a-ball/moving-the-camera?playlist=17141
     
  29. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,043
    OboShape, I truly appreciate you looking at this problem. I did file a bug but alas it has no response yet.

    Your solution does in fact cause the ball to stop rolling but it also has at least one other undesirable side effect in that the ball can also go to sleep on a incline where gravity naturally would cause it to roll down hill.

    Perhaps it's just a matter of tweaking the value I am not sure but it would be good to have Unity weigh in on this.

    Btw are you and Adam saying this issue does not happen with the roll-a-ball tutorial for which this forum thread was created? I have not done this tutorial but i did check the transcript and it appeared to me a mesh collider is being used for the ground so I figured it would have the same issue?
     
  30. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Yea, just been through it again, seems to have a similar effect, only way i stopped it was popping the Angular drag in the inspector up to 25.
    Just my ramblings of a fellow student :) Thought I might try and chip in over the holiday season, see what I could find out to try and help a bit, see what the Unity team find out after holidays, fingers crossed you get a solution.
     
    Last edited: Dec 30, 2015
  31. vmadev

    vmadev

    Joined:
    Dec 16, 2015
    Posts:
    5
    Code is code tagged. This is a new project a fresh build but still ball is not rolling no errors but the debug statements returning 0 for both the variables.
     
  32. vmadev

    vmadev

    Joined:
    Dec 16, 2015
    Posts:
    5
    There is no character controller in this new build
     
  33. lillypadmad

    lillypadmad

    Joined:
    Jan 2, 2016
    Posts:
    1
    hi i am stuck trying to move the ball, i've checked my code and i don't think there is anything wrong. can someone tell me where i went wrong?
    this is the code:

    using UnityEngine;
    using System.Collections;

    public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody rb;

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

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

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

    rb.AddForce (movement * speed);
    }
    }
     
  34. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I'll try to get a look at this today, as I'm just coming back from the Winter Holidays.
     
    ibyte likes this.
  35. Tichama

    Tichama

    Joined:
    Jan 4, 2016
    Posts:
    2
    Hi there Captain_Piff, I had same trouble, found the answer in Unity Manual under Rigidbody. In the Rigidbody properties you must un-check the box "is kinematic". As stated "If enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform"
     
  36. Tichama

    Tichama

    Joined:
    Jan 4, 2016
    Posts:
    2
    try un-checking the box "is kinematic" in the Rigidbody properties. According to Manual under Rigidbody "If enabled, the object will not be driven by the physics engine, and can only be manipulated by its Transform"
     
  37. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    @inuonlyone @IamMurloc @janineteo I can't reproduce this issue, and so far none of my colleagues can either. Can you make sure you are on a current version of Unity, and if you are still having issues, can you please file a bug report with reproducible steps?
     
  38. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Humph! I don't see anything overtly wrong with what you've presented.

    Do you have any errors in the console? Are you using the ASDW or arrow keys? Have you changed the InputManager in anyway?
     
  39. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    I don't see anything off the bat that seems wrong...

    What controls are you using to try and move the ball? Are you using the ASDW or Arrow Keys? Have you changed the Input Manager in anyway? Are any constraints set on the Rigidbody?
     
  40. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You seem to have answers to your post on, well, Answers. If you are still having trouble, post here, or tell us to look there.

    The next project should be Space Shooter.

    Space Shooter will cover Coroutines, so this may help.
     
  41. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You're the 3rd person that's had this issue, and I can't see what it is. I can only ask what I've asked before:
    • Are there any errors in your console?
    • Do you have the script attached?
    • Do you have a valid value for speed?
    • Have you accidentally checked "Is Kinematic" on the rigidbody?
    • Have you changed the Input Manager in any way, as this project assumes defaults?
    • Are you using the ASDW or Arrow Keys to move your ball?
     
  42. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Thanks for your patience. I believe I've answered this above. I have been on holiday until now.
     
  43. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    Can you please use code tags when posting code on the forum?
    http://forum.unity3d.com/threads/using-code-tags-properly.143875/
     
  44. Adam-Buckner

    Adam-Buckner

    Joined:
    Jun 27, 2007
    Posts:
    5,664
    You're the 4th person that's had this issue, and I can't see what it is. I can only ask what I've asked before:
    • Are there any errors in your console?
    • Do you have the script attached?
    • Do you have a valid value for speed?
    • Have you accidentally checked "Is Kinematic" on the rigidbody?
    • Have you changed the Input Manager in any way, as this project assumes defaults?
    • Are you using the ASDW or Arrow Keys to move your ball?
     
  45. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    1,043
    Looks like my bug report got closed as a duplicate. So I am hoping the next 5.3 patch will solve both of my problems.
     
  46. dober147

    dober147

    Joined:
    Jan 11, 2016
    Posts:
    2
    Hi. I don't get the "Win text" when i collected >= 5 pickups.
    Here is the code. pls help
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class PlayerController : MonoBehaviour {
    6.  
    7.     void OnTriggerEnter(Collider other)
    8.     {
    9.         if (other.gameObject.CompareTag ("PickUp"))
    10.      
    11.         {
    12.             other.gameObject.SetActive (false);
    13.             count = count + 1;
    14.             CountText.text = "Count " + count.ToString ();
    15.         }
    16.  
    17.     }
    18.  
    19.  
    20.     public float speed;
    21.     public Text CountText;
    22.     public Text winText;
    23.  
    24.  
    25.     private Rigidbody rb;
    26.     private int count;
    27.  
    28.  
    29.     void Start ()
    30.     {
    31.         rb = GetComponent<Rigidbody> ();
    32.         count = 0;
    33.         SetCountText ();
    34.         winText.text = "";
    35.  
    36.     }
    37.  
    38.  
    39.     void FixedUpdate ()
    40.     {
    41.         float moveHorizontal = Input.GetAxis ("Horizontal");
    42.         float moveVertical = Input.GetAxis ("Vertical");
    43.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    44.  
    45.         rb.AddForce (movement * speed);
    46.     }
    47.  
    48.     void SetCountText ()
    49.     {
    50.         CountText.text = "Count " + count.ToString ();
    51.         if (count >= 5)
    52.         {
    53.             winText.text = "You Win!";
    54.         }
    55.  
    56.     }
    57.  
    58. }
    59.  
     
    Last edited: Jan 14, 2016
  47. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Morning,

    Looking at your OnTriggerEnter function.

    You are settting the count text directly, as opposed to using the SetCountText function.
    so this function is not getting called when you collect a pickup and therefore never checking for that win state.
    Code (CSharp):
    1.  void OnTriggerEnter(Collider other)
    2.     {
    3.         if (other.gameObject.CompareTag ("PickUp"))
    4.    
    5.         {
    6.             other.gameObject.SetActive (false);
    7.             count = count + 1;
    8.             //CountText.text = "Count " + count.ToString ();
    9.           SetCountText(); // add this in stead of the line above
    10.         }
    11.     }
    fingers crossed that should be you :)
     
    Last edited: Jan 15, 2016
  48. Stephanlukas

    Stephanlukas

    Joined:
    Jan 17, 2016
    Posts:
    1
    I was unable to get the ball to roll following all of the directions. This final code matched what was played in the end, but there was an error message by rb.AddForce that said "Cannot implicitly convert type 'float' to 'UnityEngine.Vector3'. Here is the code, and if any think there is something I may need to go back over, let me know. Thanks

    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. }
    25.  
     
  49. OboShape

    OboShape

    Joined:
    Feb 17, 2014
    Posts:
    836
    Afternoon,

    what you have in your code is the following
    Code (CSharp):
    1. rb.AddForce (movement = speed);
    this is the assignment operator, this should be changed to multiplication. as the error states the float value for speed cannot be assigned to the Vector3 as they are different value types.

    as the player input floats have a maximum value of 1, and these will populate the movement Vector3 ie (1, 0, 1) so multiplying by speed will in turn multiply each member value of the Vector3 and make your ship go faster.

    Change to the following and you should be good to run about ready to shoot some baddies :)
    Code (CSharp):
    1. rb.AddForce (movement * speed);
     
  50. Ironhide

    Ironhide

    Joined:
    May 9, 2013
    Posts:
    26
    Hi!
    I'm looking for a simple script to move to another lvl when you have collected all the pieces.