I’ve started my journey with Unity a few days ago. For my first project, I decided to create a small 2d pixelart RPG game with grid based movement. For now, I’ve created a movement script using UnityEngine - StartCoroutine, Lerp etc. - its not perfect and I have to make some changes but for now I’m happy with it - works as I wanted :). My prio was to achieve diagonal movement by single key click.
After some research I’ve found a lot of materials about new Input System and these are my questions:
Does using it over pure script have any great advantages?
It is possible to achieve somehow diagonal movement by pressing single key instead of combination of two? When I’m adding Input Action it is generating for me basic movement WSAD or ARROWS and diagonal is done by W+A, W+D and so on. Can’t find a way how or if its even possible, to bind e.g
W+A diagonal movement under just Q key.
Does using it over pure script have any great advantages?
You can use the new input system entirely from script! You setup your mappings in an InputAction asset and can query it from code. See SimpleDemo_UsingActionAsset.cs in the Simple Demo example from the Input System Package examples.
If you mean better than the old input system, I’d expect the new system is more consistent across platforms? The old system doesn’t support mfi controllers or Xbox dpad on macOS, anything on iOS, and has different button layouts for many gamepad types.
If you mean using the raw Gamepad.current.gamepad.buttonSouth.wasPressedThisFrame API (seen in SimpleController_UsingState), then the benefit to InputAction is that you can support multiple input types with one configuration – your game can support keyboard and gamepad with less work.
It is possible to achieve somehow diagonal movement by pressing single key instead of combination of two? When I’m adding Input Action it is generating for me basic movement WSAD or ARROWS and diagonal is done by W+A, W+D and so on. Can’t find a way how or if its even possible, to bind e.g W+A diagonal movement under just Q key.
Use two separate bindings. Bind wasd a Vector2 like in the SimpleDemo_UsingActionAsset sample, and add qezc (or whatever your four diagonals would be) as more inputs.
If you setup four Button inputs for each diagonal direction, you could do it like this:
And in the example SimpleDemo_UsingActionAsset.cs, modify Update to be:
void Update()
{
var look = m_Controls.gameplay.look.ReadValue<Vector2>();
var move = m_Controls.gameplay.move.ReadValue<Vector2>();
// qezc. qc are x, ze are y.
// q means -x and +y - nw
// e means +x and +y - ne
// z means -x and -y - se
// c means +x and -y - sw
move.x -= m_Controls.gameplay.diagonal_nw.ReadValue<float>();
move.y += m_Controls.gameplay.diagonal_nw.ReadValue<float>();
move.x += m_Controls.gameplay.diagonal_ne.ReadValue<float>();
move.y += m_Controls.gameplay.diagonal_ne.ReadValue<float>();
move.x += m_Controls.gameplay.diagonal_se.ReadValue<float>();
move.y -= m_Controls.gameplay.diagonal_se.ReadValue<float>();
move.x -= m_Controls.gameplay.diagonal_sw.ReadValue<float>();
move.y -= m_Controls.gameplay.diagonal_sw.ReadValue<float>();
// Update orientation first, then move. Otherwise move orientation will lag
// behind by one frame.
Look(look);
Move(move);
}
There’s probably a smarter way to do it with Composite Axis (two 1D or a 2D), but it would take some figuring out.
I have already dealt with the problem. I realized that I don’t have to stick only with basic movement binding but I can also make my own, seperate bindings for diagonal movement. Now I’m trying to improve it.
In any case, thank you very much for all the explanations, they will be helpful in further work!