Sprite no longer moving left and right

Hello all,

I’m following a course from Udemy on building a 2D RPG game, and I’ve encountered a bug and would like some assistance on how to go about it.

The issue: my sprite is no longer able to move left and right, it can move up and down.

Some things I’ve tried:
1 - I’ve made a new sprite (a new gameObject) and I added a new script with the same code. This new sprite is able to move freely.
2 - I removed and re-added the Rigidbody2D component.
3 - I replaced the old script with my new script from my second sprite.
4 - Look in Debug mode of the Inspector and compared my two gameobjects.

Overall, I don’t think this is a coding issue. I think this is some issue with the game object itself.

In case you’re wondering, the code to move the sprite is quite simple:

public class NewController : MonoBehaviour
{
    public Rigidbody2D rb2;
    public float moveSpeed;
    // Start is called before the first frame update
    void Start()
    {
       
    }

    // Update is called once per frame
    void Update()
    {
        rb2.velocity = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical")) * moveSpeed;

    }
}

Something to consider:

I do have animations on my sprite, and the animations behave as expected. It walks right when pressing right, and walks left when pressing left.
Using Debug.Log(), I can print out the velocity values and the sprite is definitely registering velocity in the x component (which is also seen by the animations) but it still won’t move! I did check the Constraints in the Rigidbody2D, there aren’t any.

Thanks in advance for any help,
-Brad

Hi, wellcome to the forum

I think is a code issue, i dont like, at all, its ugly, and nothing like some i would use. If i were you i would start to search another course at udemy or anywhere else.

https://unity3d.com/es/learn/tutorials

using UnityEngine;
using System.Collections;

public class CompletePlayerController : MonoBehaviour {

    public float speed;             //Floating point variable to store the player's movement speed.

    private Rigidbody2D rb2d;       //Store a reference to the Rigidbody2D component required to use 2D Physics.

    // Use this for initialization
    void Start()
    {
        //Get and store a reference to the Rigidbody2D component so that we can access it.
        rb2d = GetComponent<Rigidbody2D> ();
    }

    //FixedUpdate is called at a fixed interval and is independent of frame rate. Put physics code here.
    void FixedUpdate()
    {
        //Store the current horizontal input in the float moveHorizontal.
        float moveHorizontal = Input.GetAxis ("Horizontal");

        //Store the current vertical input in the float moveVertical.
        float moveVertical = Input.GetAxis ("Vertical");

        //Use the two store floats to create a new Vector2 variable movement.
        Vector2 movement = new Vector2 (moveHorizontal, moveVertical);

        //Call the AddForce function of our Rigidbody2D rb2d supplying movement multiplied by speed to move our player.
        rb2d.AddForce (movement * speed);
    }
}