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

input axis horizontal is not setup pls help

Discussion in 'Scripting' started by itspicklerickandmorty, Apr 6, 2020.

  1. itspicklerickandmorty

    itspicklerickandmorty

    Joined:
    Apr 6, 2020
    Posts:
    16
    I keep getting the input axis horizontal is not setup can somebody please help me
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class Moveball : MonoBehaviour
    7. {
    8.     Rigidbody rb;
    9.     // Start is called before the first frame update
    10.     void Start()
    11.     {
    12.         rb = GetComponent<Rigidbody>();
    13.     }
    14.  
    15.     // Update is called once per frame
    16.     void Update()
    17.     {
    18.         float Hmove = Input.GetAxis("horizontal");
    19.         float Vmove = Input.GetAxis("vertical");
    20.  
    21.         Vector3 ballmove = new Vector3(Hmove, 0.0f, Vmove);
    22.         rb.AddForce (ballmove);
    23.     }
    24. }
    25.  
     
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Hey and welcome.
    Generally speaking it is advisable to post the actual error message you are getting.
    The problem you are having is because you misspelled the axis name tho. It's case sensitive, so 'horizontal' does not exist (unless you define or rename it as such), but 'Horizontal' does. The same goes for 'vertical'.

    Hope this helps :)

    Edit: That said, you may wanna look into some C# naming conventions. As a rule of thumb you want to write variables in camelCase - starting with a lower case letter and capitalizing every following 'word'. Class, method and property names are written using UpperCamelCase. Using the same conventions as others helps make your code more uniform and thus easier to understand for other programmers. It also helps to differentiate between variables and properties, or types and instances and so on.
     
    admad123 likes this.
  3. APSchmidtOfOld

    APSchmidtOfOld

    Joined:
    Aug 8, 2016
    Posts:
    4,473
    Horizontal and Vertical are case sensitive and they both begin with a capital letter. This is something you could have figured out by yourself, had you paid attention.
     
    exiguous likes this.
  4. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    In theory, all problems can be figured out by yourself if you just pay attention to details, read the documentation and occassionally read some scientific paper for algorithmic problems. However, forums exist to exchange knowledge, which also includes helping people who still struggle with the basics, and dont yet have an understanding of what an obvious solution is, or how to figure that out for themselves.
    While there are a lot of repetitive questions where i'd like people to use the search function before opening a thread, this specifically is not something that just directly jumps at your face when you google it. That said, of course, if you googled properly you would find a solution.
     
  5. APSchmidtOfOld

    APSchmidtOfOld

    Joined:
    Aug 8, 2016
    Posts:
    4,473
    No need to study algorithms to make sure you wrote your code correctly. The first things people must do before asking for help is make sure there are no typos in their code. Since I doubt the poster took his code out of nowhere, there's a big chance that he just didn't pay attention when he copied it.
     
    exiguous likes this.
  6. itspicklerickandmorty

    itspicklerickandmorty

    Joined:
    Apr 6, 2020
    Posts:
    16
    so it was my spelling or no?. because I'm still getting it. I changed horizontal to be 'Horizontal' and vertical to be 'Vertical' is there anything else I missed
     
  7. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    Yes, you wrote 'horizontal' instead of 'Horizontal'. Same for 'vertical'. I thought i made that very clear tho.
    Not to mention that another person answered the exact same thing.
    And you could also just quickly test it in a fraction of the time anybody could answer in.
     
  8. itspicklerickandmorty

    itspicklerickandmorty

    Joined:
    Apr 6, 2020
    Posts:
    16
    sorry that I edited it after you replyed but there is now more to add to it
     
  9. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    So your line now looks like this and you are still getting the error?
    Code (CSharp):
    1. float Hmove = Input.GetAxis("Horizontal");
    You are only supposed to capitalize the 'h'.
     
  10. itspicklerickandmorty

    itspicklerickandmorty

    Joined:
    Apr 6, 2020
    Posts:
    16
    ok i fixed it now thanks for the help you where great at explaing it to me