couldn’t figure out the new system.
for one, I use Actions | Input System | 1.0.2 Button.
Also see Enum InputActionType | Input System | 1.0.2
As I use Actions | Input System | 1.0.2, I set Button on the GO:
Using Push Events, this might be enough. GameObject components for input | Input System | 1.0.2 You don’t need a PlayerInput
though, you can simply add event listeners to your MonoBehaviour-based Action, if you went my route: Actions | Input System | 1.0.2
However, I use polling: Actions | Input System | 1.0.2, I converted my Update() GetKeyDown() to
if (iA_rotate.ReadValue<float>() == 1)
{
if (wasNotYetRead) {
wasNotYetRead = false;
// do stuff
}
}
else
{
wasNotYetRead = true;
}
using a shielding flag.
an Action in the new Input System corresponds to an Axis in the old Input Manager. In that IM, the Axis bound to up to 4 keyboard keys and took input from any Gamepad and mouse simultaneously. In the IS, you can (and must) bind every device key/button/stick you like to get data from explicitly to the Action yourself.
The value range is [0,1] for the most part (key not pressed = 0, key pressed = 1), [-1, 1] for sticks I guess (haven’t verified this).
To emulate sensitivity and gravity of an Axis of the IM, use sth. like this:
accumulatedRollLeft += (rollleft.ReadValue<float>() * 2f - 1f) * Time.deltaTime;
accumulatedRollLeft = Mathf.Clamp01(accumulatedRollLeft);
This emulates sensitivity and gravity of 1. The arithmetic maps [0,1] to [-1,1], ensuring key not pressed returns the value to 0. Clamping prevents overflow.
How can i implement this, given the fact that i don’t use the classic method of referencing the asset and doing the action.started += ‘callback function’… but instead i use the PlayerInput component’s Events > Player Callbacks, (the ones that take a parameter of type CallbackContext)
here’s the part of script of my concern:
private PlayerMotor Motor;
public void OnMovement_H(InputAction.CallbackContext context) {
float _direction = context.ReadValue<float>();
Motor.Aim_H(_direction);
}
The action that triggers the OnMovement_H method’s Action Type is set to Button and it has one 1D Axis Composite
is _direction either 0 or 1 currently?
if yes, replace rollleft in my code by context from yours and store accumulatedRollLeft as a class float initialised as 0.
register delegate, onevents… seems awfully complicated for quick work, how is it in actual production?
UnityEngine.InputSystem.Keyboard.current.akey.wasPressedThisFrame
Im not at the computer at the moment, but I believe thats the full path. Thats the easy way to quickly setup input without using the Actions or anything.
Can also get to gamepad, etc through similar ways.
nice!
now how do I get the vector2 from this thing?
like that
answer:
var input = UnityEngine.InputSystem.Gamepad.current.leftStick.x.EvaluateMagnitude();
a mouthful. There is a very good blog on this:
https://blog.eyas.sh/2020/10/unity-for-engineers-pt3-input-system/
Ahh nice! I didnt know about that. Like your link describes, I typically use ‘ReadValue’:
Using UnityEngine.InputSystem;
(...)
var input = Gamepad.current.leftStick.ReadValue();
EvaluateMagnitude is abs of ReadValue?
what’s the purpose of either?