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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Movement input

Discussion in 'Scripting' started by LudicrusGamer, Dec 16, 2016.

  1. LudicrusGamer

    LudicrusGamer

    Joined:
    Dec 16, 2016
    Posts:
    4
    Hi there

    im sort of new to this whole thing, decided to try to use some of the tutorials to get an idea.

    So doing the roll-a-ball thing right now. finished most of it just having trouble with moving the ball. I don't know how to set up my input command. Sure i got one from the asset store, but made no difference.

    Help.

    Kind regards
     
  2. Joboto

    Joboto

    Joined:
    Sep 12, 2013
    Posts:
    64
    Hey,

    Can you post an example of what you are doing? It's not clear to me where you are needing a hand.

    Cheers
     
  3. LudicrusGamer

    LudicrusGamer

    Joined:
    Dec 16, 2016
    Posts:
    4
    Ill clear it up a bit then.

    Earlier today i was working on the script for the game to get ball to roll, i had a few issues by i managed to get them fixed later. After i finished the scrip, the ball was supposed to move. When ever i try to play test it the console tells me that there is a problem on line 21. Now i am not sure what that problem is but ill post the message along with the scrip.

    NullReferencEexception: object reference not set to an instance of an object.

    Maybe a pair of experienced eyes will see more than I.
     

    Attached Files:

  4. Joboto

    Joboto

    Joined:
    Sep 12, 2013
    Posts:
    64
    Hi,

    from the exception message I can surmise that its like you have are trying to use an object that doesn't exist at the time line 21 executes.

    This can usually occur with one of the following:
    • You have a public/ or serialized private variable exposed to the inspector window but haven't dragged a reference to the object into it in the editor.
    • You are using a GameObject.Find style method to find an object that doesn't exist at the moment.

    If you can debug the script or place a Debug.Log([object]) before the line in the code that its complaining about it should reveal the problem.

    Steps I would take would be:
    • Identify which object is null through debugging (or Debug.Log()s).
    • Find out how it should be made available (either through the inspector window or from script)
    • Correct it by dragging the object into the slot or making it available to do so
    https://unity3d.com/learn/tutorials/topics/scripting/monodevelops-debugger
    https://docs.unity3d.com/Manual/EditingValueProperties.html
    https://docs.unity3d.com/Manual/NullReferenceException.html

    I'm not familiar with the ball roll code base but if you need further help, if you can post the code you've written I should be able to help further.

    Kind Regards,
     
  5. Joboto

    Joboto

    Joined:
    Sep 12, 2013
    Posts:
    64
    Apologies, just noticed that you've already posted the code, I'll have a look.
     
  6. Joboto

    Joboto

    Joined:
    Sep 12, 2013
    Posts:
    64
    Looking at your code, the PlayerControler object needs a RigidBody component to move.

    I believe its because you have used a lowercase "void start()" method. In c# methods are case sensitive. Unity will be looking to use "void Start()" to initialize your object. So your code that gets the Rigidbody component is likely not running.

    Either that or there is no Rigidbody component attached to PlayerControler in the editor.

    Kind Regards,
     
  7. LudicrusGamer

    LudicrusGamer

    Joined:
    Dec 16, 2016
    Posts:
    4
    Thx

    Ill try that.

    Ok, now i think i am getting to the root of the problem, which apparently is rb and ';' being recognized as an unexpected symbol. This seems to prevent the whole script from running. I got a few ideas as to why this is happening and will try to fix it.

    I am open to suggestions.
     

    Attached Files:

  8. LudicrusGamer

    LudicrusGamer

    Joined:
    Dec 16, 2016
    Posts:
    4
    Thx for you help Mr.Jobot.
    I found the error that was preventing my object to move. i mistyped the script for Rigidbody as private instead of public. it works now.

    Kind regards
     
  9. Joboto

    Joboto

    Joined:
    Sep 12, 2013
    Posts:
    64
    No problem at all.

    Its strange that private caused the problem as that should still be fine in the context of your code. Perhaps an illegal character was pasted in that caused the issue and it was fixed by removing it and typing public.

    Regardless, glad its now working for you

    Kind Regards,
     
  10. jojoofu

    jojoofu

    Joined:
    Oct 9, 2016
    Posts:
    8
    Last edited: Dec 18, 2016
  11. karmacomp

    karmacomp

    Joined:
    May 2, 2014
    Posts:
    43
    Is there any tutorials or assets to allow a non-biped 3rd person controller? Namely, I want a CAT to be the third person character. I chose Cu-Cat2 as the cat asset.

    How would I make a 3rd person camera that would follow the animated cat around and allow the player to use the mouse and keyboard to control it?

    Does such an asset or tutorial exist?

    Thank you.

    Mike