I am new to Unity and programming. While I think I’m getting pretty good at programming, I still can’t code basic things without a tutorial. I have been making a 2D top-down shooter like Enter the Gungeon and I’ve used Brackey’s top-down shooter tutorial to implement character movement. While it has worked reliably on my other projects, I’ve encountered a bug that hasn’t happened to me before. The character’s x and y values increase slightly even without input, causing them to move toward the top-right corner. I’m not sure how to fix it, but I have determined that it is because of the code. I think it might have something to do with the new input system, as that is the only difference from the last few times I used it.
[SerializeField] private float moveSpeed = 15f;
[SerializeField] private Rigidbody2D rb;
Vector2 movement;
public InputAction Controls;
private void OnEnable()
{
Controls.Enable();
}
private void OnDisable()
{
Controls.Disable();
}
// Update is called once per frame
void Update()
{
movement = Controls.ReadValue<Vector2>();
}
private void FixedUpdate()
{
rb.velocity = new Vector2(movement.x * moveSpeed + Time.deltaTime, movement.y * moveSpeed + Time.deltaTime);
}
}
Thank you for your help!