- Home /
Customized input axes aren't working
For the horizontal and vertical axes, all I did was change the name. I also added my own and they aren't working either.
Relevant code:
float forwardInput;
float rightInput;
float rightInputUpdate;
float cameraMoveSensitivity;
GameObject mainCamera;
private void Awake()
{
cameraMoveSensitivity = 1; //temp; allow player customization of sensitivity
cameraMoveSensitivity *= 10;
mainCamera = GameObject.Find("Main Camera");
}
void Update()
{
//this is the old input code that I want to replace with axes
if (Input.GetKeyDown(KeyCode.D)) rightInput += 1; if (Input.GetKeyUp(KeyCode.D)) rightInput -= 1;
if (Input.GetKeyDown(KeyCode.A)) rightInput -= 1; if (Input.GetKeyUp(KeyCode.A)) rightInput += 1;
if (!mainCamera)
Debug.LogError("Main Camera not found");
else
{
rightInputUpdate = rightInput * cameraMoveSensitivity * Time.unscaledDeltaTime * mainCamera.transform.position.y / cameraShiftModifier;
forwardInput = Input.GetAxis("Forward Translate") * cameraMoveSensitivity * Time.unscaledDeltaTime * mainCamera.transform.position.y / cameraShiftModifier;
}
transform.Translate(rightInputUpdate, 0, forwardInput);
print(Input.GetAxis("Forward Translate"));
}
Lines 25 and 28 are where the custom axis is written.
Right input works and the camera translates left to right with the a/d keys, but w/s don't work and the camera doesn't translate forward and back. The print function also only prints 0.
capture.png
(11.7 kB)
Comment