- Home /
Question by
vetalsm2009 · Mar 15 at 10:24 AM ·
c#controllerfloats
What's wrong with this code? In the end forwardInput must be 0 but in unity it becomes 1 and I don't click anything.
![alt text][1]using System.Collections; using System.Collections.Generic; using UnityEngine;
public class PlayerController : MonoBehaviour { public float speed; public float turnSpeed; public float horizontalInput; public float forwardInput;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.forward * Time.deltaTime * speed * forwardInput);
transform.Translate(Vector3.right * Time.deltaTime * turnSpeed * horizontalInput);
}
}
2022-03-15.png
(161.0 kB)
2022-03-15-4-1.png
(225.7 kB)
Comment
This code is working as expected on my side i.e. forwardInput is 0 when nothing clicked and changed to 1 when 'W' is pressed. Can you send a snapshot of you Input Manager's vertical values? (Edit->Project Settings -> Input Manager)
Nothing wrong here. Can you try this same script in a new project on a simple cube. It might be cause of any other script or some thing else. Sorry, I know this is not that much of a help.
Your answer
