Keyboard input not working even with basic keys

So I’m following this tutorial here: http://unity3d.com/learn/tutorials/projects/roll-a-ball/moving-the-player

the problem I have is that the game does not seems to be picking up my keyboard. No matter what button I push, I can’t get it to pick up input. Any suggestions?

Input code from the Tutorial:

using UnityEngine;
using System.Collections;

public class PlayerInput : MonoBehaviour 
{
	public float speed;
	void update()
	{

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

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

		rigidbody.AddForce (movement * speed);


	}
}

this tutorial and also the other tutorial with which I had the same problem (Introduction & Setup - Unity Learn) teach you to change the speed variable using the inspector.

Problem is: it defaults to 0 (no speed, so no movement). So you need to set it to something useful.

Good day, The problem is that your code is good, more than good excellent, but I was testing it and I realized two things nothing concerning problems in code:

1 - The variable “Speed” originally is empty. It ensures that you have increased its value in the inspector.

2 - This is the most important causes immobilization:

rigidbody.AddForce (movement speed);

This line of code is a bit erroneous. if you use Unity 5, the line is transformed into:

GetComponent () AddForce (movement speed);

And finally you must add the “RigidBody” component in the GameObject you add this script.

I hope you have been helpful and it work. Will it work :slight_smile:

Go to:

Edit > Project Settings > Input

Check to make sure that for the ‘Horizontal’ and ‘Vertical’ axes, that the ‘Type’ is set to ‘Key or Mouse Button’, and not to ‘Mouse Movement’ or ‘Joystick Axis’

public class PlayerMovement : MonoBehaviour

{
public float speed = 6f;

Vector3 movement;
Animator anim;
Rigidbody playerRigidbody;
int floorMask;
float camRayLength = 100f;

void Awake()
{
    floorMask = LayerMask.GetMask("floor");
    anim = GetComponent<Animator>();
    playerRigidbody = GetComponent<Rigidbody>();
}

void FixedUptade()
{
    float h = Input.GetAxisRaw("Horizontal");
    float v = Input.GetAxisRaw("Vertical");

    Move(h, v);
    Turning();
    Animating(h, v);

}

void Move (float h, float v)
{
    movement.Set(h, 0f, v);

    movement = movement.normalized * speed * Time.deltaTime;

    playerRigidbody.MovePosition(transform.position + movement);
}

void Turning()
{
    Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition);

    RaycastHit floorHit;

    if (Physics.Raycast (camRay, out floorHit, camRayLength, floorMask))
    {
        Vector3 playerToMouse = floorHit.point - transform.position;
        playerToMouse.y = 0f;

        Quaternion newRotation = Quaternion.LookRotation(playerToMouse);
        playerRigidbody.MoveRotation(newRotation);
    }
}

void Animating(float h, float v)
{
    bool walking = h != 0f || v != 0f;
    anim.SetBool ("IsWalking", walking);
}

}

Aint working, Movement based keys or nothing on play mode, Done 2-3 Tutorials the rolling ball and space shooter, following intructions perfectly, each time game cant be played with the keys set in unity.

My script was not attached. It looked fine but would not work. I dragged the script onto the sphere for the first tutorial game and it worked. Also then put the variable into the Script inspector for speed. Frustrating but it finally moved!

So i had this same problem… unity refused to identify key presses from my keyboard, or identify my android back button … I did testing in an update function that was

       if (Input.anyKey)
        Debug.Log("A key was pressed");

With this, unity would respond to mouse clicks in my scene, but not the keyboard, and still no android back button … one answer that previously worked was related to the event manager needing to be forced active at all times, but not so lucky for an easy answer this time… So i copied my project data into a new unity project and it worked as intended… go figure…

So after 3 days of looking for answers and doing what people think was the problems solution was across nearly 100 posts for this relative question, i finally resolved this problem by deleting the library folder for my project and allowing unity to recompile the whole project. After doing this, everything worked as intended.
It is worth noting that in my case, it was not enough to re import the project, if you have reached your wits end and exhausted all other options you NEED to delete the library folder. This will not harm your project in any way.

Check the below link it will explain the basic of input from keyboard Keyboard input in game

I’m working on this tutorial: Environment and Player - Unity Learn
My code would not work either and the code was just like the tutorials, even tried copy/pasting it. The error I got in the Console was:

MissingComponentException: There is no 'Rigidbody' attached to the "Player" game object, but a script is trying to access it.
You probably need to add a Rigidbody to the game object "Player". Or your script needs to check if the component is attached before using it.
UnityEngine.Rigidbody.AddForce (Vector3 force) (at C:/buildslave/unity/build/artifacts/generated/common/modules/Physics/DynamicsBindings.gen.cs:1263)
PlayerController.FixedUpdate () (at Assets/Scripts/PlayerController.cs:23)

For some reason, the tutorial does not mention that a RigidBody needs to be added to the Ball in Unity 5.5.1f1. Below are steps on how to add it in:
0) Select the Player ball

  1. Click on the Add Component button in the Inspector
  2. In the search area next to the magnifying class, type in “rigid” to search
  3. Click on the Rigidbody option
  4. The new component is now listed in the inspector and the ball rolls!

Screenshot:

Below is my code:

using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour
{
    public float speed = 10;
    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);
    }
}