Hi, I have some code for controlling player’s movement but there is one problem - the keys are set fixed in code and generally can’t be changed. I know that Unity has something like Input.GetAxis() method where I can use “Horizontal” or “Vertical” keys. According to this, I can change keys via Application Config Dialog which is fine because game could be playable via keyboard or gamepad.
I’m thinking about using GetAxis methods but I don’t have any idea how to change the code below. The idea should be the same as it’s current. Could you suggest me how I can rewrite this code to use Input.GetAxis for horizontal?
if (Input.GetKey("Q")) {
rigidBody.AddForce(-myForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if (Input.GetKey("W")) {
rigidBody.AddForce(myForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}