For some reason, I can never get movement to capture/recognize any key input. Are there any common reasons I can investigate?
I’ve confirmed the ‘Player’ setting is set to the ‘both’ option for input handling. My code does not generate any debugger errors. I’ve tried setting the input action to WASD and arrow keys. PlayerController and RigidBody is attached to the player sprite. I can accomplish movement by passing in a dummy Vector2 object, but I cannot get movement to report any new values from the keyboard input.
Here is my code:
public class PlayerController : MonoBehaviour
{
[SerializeField] private float moveSpeed = 1f;
private PlayerControls playerControls;
private Vector2 movement;
private Rigidbody2D rb;
private void Awake() {
playerControls = new PlayerControls();
rb = GetComponent<Rigidbody2D>();
}
private void onEnable() {
playerControls.Enable();
}
private void OnDisable() {
playerControls.Disable();
}
private void Update() {
PlayerInput();
}
private void FixedUpdate() {
Move();
}
private void PlayerInput() {
movement = playerControls.Movement.Move.ReadValue<Vector2>();
Debug.Log(movement.x);
}
private void Move() {
rb.MovePosition(rb.position + movement * (moveSpeed * Time.fixedDeltaTime));
}
}
Here is the Player Controls