Hi everyone,
This is an issue many already experienced apparently and different people found different solutions. I can’t find mine at the moment however.
Apparently I had a duplicate Horizontal in the Input Manager, which I removed. This did not solve the issue and unfortunately I am still getting 0 when I press a or d. I also reset the playerprefs.

Any idea what the issue could be?
Thx in advance
Unless you show the code that actually accesses Input, there’s nothing we can do except guess that you misspelled ‘horizontal’.
1 Like
Hi,
Having a second Horizontal input can be used for more ways to use the Horizontal axis, getting a return value of 0 means that your code never registers the button press.
float movement = Input.GetAxis(“Horizontal”);
Debug.Log(movement);
This should return a value if you’re pressing any of the horizontal inputs but this may be a problem in your code, please share or check if there is another condition preventing the input.
Hi,
The reason why I did not share the full code is because even using a simple:
void Update()
{
Debug.Log(Input.GetAxis("Horizontal"));
}
won’t work. This returns 0 when I press a or d.
This is the full code, but I don’t think it will be of any help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FreeCam : MonoBehaviour
{
[SerializeField]
private GestoreLivello gestoreLivello;
public float cameraSensitivity = 90;
public float climbSpeed = 4;
public float normalMoveSpeed = 10;
public float slowMoveFactor = 0.25f;
public float fastMoveFactor = 3;
private float rotationX = 0.0f;
private float rotationY = 0.0f;
private void OnDisable()
{
gestoreLivello.CambiaStato(StatoLivello.InPausa);
}
void Start()
{
Cursor.lockState = CursorLockMode.Confined;
rotationX = transform.localRotation.eulerAngles.y;
rotationY = -transform.localRotation.eulerAngles.x;
}
void Update()
{
if (!Input.GetMouseButton(1))
{
return; //During testing I always press the right mouse button to be sure the code continues below
}
Debug.Log(Input.GetAxis("Horizontal"));
rotationX += Input.GetAxis("Mouse X") * cameraSensitivity * Time.unscaledDeltaTime;
rotationY += Input.GetAxis("Mouse Y") * cameraSensitivity * Time.unscaledDeltaTime;
rotationY = Mathf.Clamp(rotationY, -90, 90);
transform.localRotation = Quaternion.AngleAxis(rotationX, Vector3.up);
transform.localRotation *= Quaternion.AngleAxis(rotationY, Vector3.left);
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
transform.position += transform.forward * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Vertical") * Time.unscaledDeltaTime;
transform.position += transform.right * (normalMoveSpeed * fastMoveFactor) * Input.GetAxis("Horizontal") * Time.unscaledDeltaTime;
}
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
transform.position += transform.forward * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Vertical") * Time.unscaledDeltaTime;
transform.position += transform.right * (normalMoveSpeed * slowMoveFactor) * Input.GetAxis("Horizontal") * Time.unscaledDeltaTime;
}
else
{
transform.position += transform.forward * normalMoveSpeed * Input.GetAxis("Vertical") * Time.unscaledDeltaTime;
transform.position += transform.right * normalMoveSpeed * Input.GetAxis("Horizontal") * Time.unscaledDeltaTime;
}
if (Input.GetKey(KeyCode.Q)) { transform.position -= transform.up * climbSpeed * Time.unscaledDeltaTime; }
if (Input.GetKey(KeyCode.E)) { transform.position += transform.up * climbSpeed * Time.unscaledDeltaTime; }
//if (Input.GetKeyDown(KeyCode.End))
//{
// Cursor.lockState = (Cursor.lockState == CursorLockMode.Confined) ? CursorLockMode.None : CursorLockMode.Confined;
//}
}
}
Hi if this problem is still a thing then I just tried running your code and it works just fine, I might have suggested that maybe the script isn’t on any object but you still get 0s in the log. I’d suggest checking if there is a space after the Horizontal in the input manager or creating a new axis and rebinding it to a&d.
Check in your InputManager file in the projectsettings folder in your project folder. Whenever you change anything in the Input Manager, it saves to this.
I originally ‘strip’ out anything in there by default and give them better names.
Thanks for your inputs!
Eventually I had found the solution and it was related to the fact that the delta time factor was returning 0 due to being in pause… So Input Manager was actually alright, time was messing up the whole script actually.
Thanks again
1 Like
Same problem, same solution! Thank you!
I am facing the same issue.
Why Input.GetAxis(“Horizontal”) and Input.GetAxis(“Vertical”)
returning 0 when Time.timescale is 0?
Though Input.GetAxis(“Mouse X”) and Input.GetAxis(“Mouse Y”) working fine.
Only in Update, but in FixedUpdate both don’t work (it make only single run if timeScale is 0). This only suggest that FixedUpdate is for Input handler (always some extra reason).
I had a similar problem because the game mode was “Simulator” - when I switched to “Game” everything worked
1 Like
@unity_0E3A2C5490BB880A9C76 thanks, that was it :facepalm: