Hello, so I was following a tutorial and did the same code as them but have different results. I bound the Input system for wasd and the keys work but when I let go the object keeps moving. I believe the issue is on the press it gets the vector information for velcoity but it never resets it so it keeps going but the guy in the tutorial wrote it this way and had no issue. Thoughts?
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class Player : MonoBehaviour
{
private InputMaster controls; //New input action system
private Vector2 moveAxis; //2D axis to be generated from input actions
private float speed = 5.0f;
void Awake()
{
controls = new InputMaster();
controls.Player.Movement.performed += HandleMoved;
}
void Update()
{
transform.position += new Vector3(moveAxis.x, 0, moveAxis.y) * Time.deltaTime * speed;
}
private void HandleMoved(InputAction.CallbackContext context)
{
moveAxis = context.ReadValue<Vector2>();
}
private void OnEnable()
{
controls.Enable();
}
private void OnDisable()
{
controls.Disable();
}
}
So what happens is my update always uses the vector it grabbed when I pushed the key and just keeps pushing the object that way but in the tutorial whenever the guy let go the object stopped and he didnt reset the vector anywhere in the code.