- Home /
GetAxis not detecting keyboard input
I'm following unity's Create with Code tutorial, and am currently try to move the truck through player input. Neither Visual Studio nor Unity are giving me any errors or warnings. I have made sure to go into project settings and set input type to key or mouse button.
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowPlayer : MonoBehaviour {
public GameObject player;
public Vector3 offset = new Vector3(0, 5, -7);
public float turnspeed;
public float horizontalInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
transform.position = player.transform.position + offset;
transform.Translate(Vector3.right * Time.deltaTime * turnspeed * horizontalInput);
}
}
,
Answer by JoltenDev · Feb 24, 2020 at 06:32 AM
You're merging your follow player script and player controller script, you've put the input code in the follow player so what I imagine is that the code is currently trying to move the camera instead of the car. I suggest restarting the tutorial if you haven't to try to get a better understanding. :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612223851im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
how to stop motion smoothing with GetAxis? 1 Answer
Having trouble with multiple keys for one command 1 Answer
GetAxis for MouseX for web player. 0 Answers
How to put limits in Z? 0 Answers
Detecting cross platform input? 0 Answers