keyboard input not moving object
So here is my code and a view of my inspector for my sphere that I am trying to get rolling around with the roll a ball tutorial. Also an image of my input settings. When I press the W button I get the message "W is pressed" and when I release the button I get the message "W is released"; however, the sphere does not move around. I can get similar messages with other buttons but still no movement. I have adjusted the speed to various values and I have seen similar posts and tried many of the solutions offered but with no success. I am using Windows 10 and Unity 5.3.5f1. Any assistance would be greatly appreciated. Thank you.
Code:
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
private Rigidbody rb;
void start()
{
rb = GetComponent<Rigidbody>();
}
void Update()
{
if (Input.GetKeyDown(KeyCode.W))
Debug.Log("W is Pressed");
if (Input.GetKeyUp(KeyCode.W))
Debug.Log("W is released");
}
void fixedUpdate()
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce(movement * speed);
}
}
!
Answer by Anas173 · Jul 17, 2016 at 07:50 AM
float speed = 5;
Update()
{
float horizontal = input.GetAxis("Horizonta") * speed * time.deltatime;
float vertical = input.GetAxis("Vertical") * speed * time.deltatime;
vector3 pos = new vector3 (horizontal,0vertical);
transform.translate(pos);
}
Your answer

Follow this Question
Related Questions
How can I use a navmesh with keyboard input to move an object? 1 Answer
Remap keyboard/keys for InputField 0 Answers
Input Manager - prevent keyboard keys mapping to Xbox controller buttons 1 Answer
A keybinding system in unity 1 Answer
How to make GetAxis double tap dash/ reset dash speed upon release GetKeyUp?? 2 Answers