I’m migrating over to the new Unity Input system and I’ve gotten it to a reasonable point.
Currently WASD/Arrow keys move the camera rig transform about and it works as expected:
if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
{
_newPosition += (transform.forward * movementSpeed);
}
For the new input system I have setup all of the prerequisite assets, action maps, actions and bindings. I have a “Pan” action which is set up as a 2D Vector composite and I have set up bindings for up, down, left, right which are mapped to w, s, a, d respectively.
The actions are enabled and and I have a performed
and canceled
handler which both call a function called HandlePan
which sets a Vector2
called _newPosition
.
The new code, which directly replaces the Input.GetKey
code above looks like:
if (_panAxis.y > 0)
{
_newPosition += (transform.forward * movementSpeed);
}
This all works as expected, but I am doubting myself and I want to make sure I’m doing it right, or whether there is a different approach that is recommended.
Thanks!