Player wont move

I can’t seem to figure out why keyboard input isnt being captured for the player movement. Nothing is going to the Debug.Log so im assuming its my code or mapping but cant see where … Player sprite has rigid body and Player Controller script assigned to it

PlayerController Code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

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));

    }

}

It seems to have resolved itself. I added another logging line and it didnt generate anything in the console so i took it back out and closed VS Code again, at which point the script recompiled and my lil dude moved around.

Is there a way to force the scripts to compile/build after having changed code?

Welcome to the community. If you save the script in VS code and then go back to the unity editor, it will recompile automatically. You should not have to close vs code. Just switch back and forth between vsc and unity.

Hey, Ed. Thanks for the welcome.

I had been saving and then exiting, maybe its a bit buggy, or maybe im gaslighting myself. Ill be more vigilant as keep learning. im sure there’ll be a new unity version soon enough if it is a bug :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms