#Input System Character Controller
1 messages · Page 1 of 1 (latest)
How do the movement values make it into an update function? I'm not familiar with this pattern.
There are a few ways you can do it. The simplest is to set a field when an event is triggered (such as pressing w or pushing your joystick forward)
Vector2 moveVect = ctx.ReadValue<Vector2>(); That does it locally, to do it globally in the containing class:
public class PlayerInputSystem : MonoBehaviour
{
public PlayerInputActionMap PlayerInputActionMap;
Vector2 movement;
private void Awake() {
PlayerInputActionMap = new PlayerInputActionMap();
}
private void Update(){
ExampleMovePlayerMethod(movement); // Move the player
}
private void OnEnable() {
PlayerInputActionMap.Enable();
PlayerInputActionMap.Player.Move.performed += MovePressed;
PlayerInputActionMap.Player.Move.canceled += MoveUnpressed;
}
private void OnDisable() {
PlayerInputActionMap.Disable();
PlayerInputActionMap.Player.Move.performed -= MovePressed;
PlayerInputActionMap.Player.Move.canceled -= MoveUnpressed;
}
private void MovePressed(InputAction.CallbackContext ctx) {
movement = ctx.ReadValue<Vector2>();
//...do stuff, like pass moveVect to player script
}
private void MoveUnpressed(InputAction.CallbackContext ctx) {
movement = Vector2.zero;
// You dont need to call ReadValue since it will always report the default value (in this case Vector2.zero)
// .. do stuff
}
}