I've been going through the docs and anything related to the new input system. I understand it's fairly new and there were a lot of changes on 1.0.0.
I'm just starting out in Unity after a long break and to start I've been trying to move a Player around. I got it to work but it doesn't stop after releasing the keyboard key.
I didn't change anything from the default InputActions settings at first.
I did try changing the Interactions to Press > Press & Release and I got it woking but if I pressed the right key, for example, and kept it pressed while changing keys (direction) it kept moving in the right direction. I quit this because it said to just use 'Button' action type but it changes the whole setup for WASD.
And this is my player script. It might not have anything to do with the input system and everything to do with my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerBehaviour : MonoBehaviour
{
private InputActions _controls;
private Vector2 movementInput;
public float _speed = 12f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void OnEnable()
{
_controls = new InputActions();
_controls.Player.Move.performed += ctx => movementInput = ctx.ReadValue<Vector2>();
_controls.Player.Move.Enable();
}
void Update()
{
Debug.Log("transform.position: " + transform.position);
transform.position += new Vector3(movementInput.x * _speed * Time.deltaTime,
0,
movementInput.y * _speed * Time.deltaTime);
}
private void OnDisable()
{
_controls.Player.Move.Disable();
}
}
Update: I've been working on this and added more but couldn't get past my original issue.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
private InputActions _controls;
private Vector2 movementInput;
public float _speed = 12f;
public CharacterController controller;
public Camera playerCamera;
private Vector2 lookPosition;
private float mouseSensitivity = 50f;
float xRotation = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void OnEnable()
{
_controls = new InputActions();
_controls.Player.Move.performed += ctx => movementInput = ctx.ReadValue<Vector2>();
_controls.Player.Move.Enable();
_controls.Player.Look.performed += ctx => lookPosition = ctx.ReadValue<Vector2>();
_controls.Player.Look.Enable();
}
void Update()
{
float x = movementInput.x;
float z = movementInput.y;
Vector3 move = transform.right * x + transform.forward * z;
controller.Move(move * _speed * Time.deltaTime);
float lookX = lookPosition.x * mouseSensitivity * Time.deltaTime;
float lookY = lookPosition.y * mouseSensitivity * Time.deltaTime;
xRotation -= lookPosition.y;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
playerCamera.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
transform.Rotate(Vector3.up * lookX);
}
private void OnDisable()
{
_controls.Player.Move.Disable();
_controls.Player.Look.Disable();
}
}

