nicobu
February 27, 2020, 7:15pm
1
Hi all,
I probably have a simple problem. I am trying to set up the new Input System so that i can press the arrow keys to move around and press control + arrow keys to attack in a certain direction. My Input Actions look like in the attached screenshot.
My Controller script looks like that:
public void OnMoveLeft(InputAction.CallbackContext context) {
if(context.performed) {
Move(Direction.West);
}
}
public void OnForceAttackWest(InputAction.CallbackContext context) {
if(context.performed) {
Debug.Log(string.Format("OnForceAttack{0}", "West"));
}
}
Pretty straight-forward. However, when I press leftCtrl+arrow key, the movement AND the force attack execute. How can I prevent that?
Thanks
Nico
There’s a few ways to workaround this until they release an official fix for it after 1.0.
Here’s the solution I went with:
What I ended up doing was to override the Keyboard layout and add a new inverted synthetic control that returns 1 if no modifiers are pressed and 0 if any of them are. Then I can just use the standard “Button with One Modifier”.
When I don’t want a modifier pressed, I set the Modifier path to “/noModifier”.
It’s only set up to work with the keyboard modifiers, but it’s good enough for me until an official solution comes out.
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine;
using …
You should be able to find some other workarounds in the forum if you don’t like this one.
1 Like
nicobu
February 29, 2020, 10:46pm
3
Thanks!
I did actually end up with a much easier solution. I added a ToggleAttackMode Action and changed my code like this:
public void OnToggleAttackMode(InputAction.CallbackContext context) {
if(context.started) {
// button pressed
Mode = PlayerMode.Attack;
}
if(context.canceled) {
// button released
Mode = PlayerMode.Default;
}
}
public void OnActionLeft(InputAction.CallbackContext context) {
if(context.performed) {
if(Mode == PlayerMode.Default) Move(Direction.West);
else if(Mode == PlayerMode.Attack) {
if(EquipmentSlots.AttackType == AttackType.Melee) MeleeAttack(Direction.West);
else if(EquipmentSlots.AttackType == AttackType.Ranged) RangedAttack(Direction.West);
}
}
}