0
\$\begingroup\$

I'm trying to use a simple code example to move a square object like this:

public GameObject note1;
Vector2 move;

void Update()
{
    // move with keyboard
    float x = Input.GetAxis("Horizontal");
    float y = Input.GetAxis("Vertical");

    Debug.Log(x);
    Debug.Log(y);

    move = new Vector2(x, y);

    Debug.Log(move);

    note.transform.Translate(move * 1 * Time.deltaTime);
}

I check my configuration in the project settings and input manager:

Input manager screenshot

But I"m confused about three things:

  • Why do I have 2 declarations for Horizontal and Vertical input?

  • Why does my Keyboard not move the square, even though I have the config ready and I'm using matching strings in my code?

  • Why does the Debug.Log always report (0, 0)?

\$\endgroup\$
4
  • \$\begingroup\$ The two declarations for horizontal and vertical input give you multiple synonymous controls — so pressing the arrow keys OR wasd OR using the analog stick on a gamepad will all work to move your character. \$\endgroup\$ Commented Jul 8, 2023 at 19:13
  • 1
    \$\begingroup\$ What is note and where do you get/ assign it? \$\endgroup\$ Commented Jul 8, 2023 at 21:29
  • \$\begingroup\$ I note that you've changed the second Horizontal input from its default values. "Type" for that one should be "Joystick Axis" not "Key or Mouse Button" like its keyboard counterpart. But that error does not account for the symptoms you report. \$\endgroup\$ Commented Jul 9, 2023 at 0:20
  • 1
    \$\begingroup\$ Your public variable note1 is a different one than the one you use in update \$\endgroup\$ Commented Jul 9, 2023 at 8:54

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.