TileVania - Left / Right movement

I have gone back over a few parts of the class and for some reason I cannot move my player left and right. No issues when it came to up/down. I have looked at the colliders with no luck. Let me know what I can post to help with this :frowning:

1 Like

If you can post a screenshot of your code and that should help me solve your issue

1 Like

Hi Rick,

Welcome to our community! :slight_smile:

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture? Have you already tried to add Debug.Logs to your code to see what is going on during runtime? And are there any error messages in your console?


@Christopher_Powell, no screenshots, please. Code as formatted text would be great. This way, we will be able to copy and paste lines if necessary. With screenshots, we would have to type everything, which will very likely introduce typos. Reading long texts on screenshots is also exhausting for many people.

2 Likes

Oh yeah my bad, must have just been a habit to say something like that, I also don’t mind reading through them, but from now on I’ll try to remember to ask for formatting.

2 Likes

I did some compares and I did not see anything out of place. The Debug Logs looked good

debug_log

The code for the PlayerMovement.cs is

public class PlayerMovement : MonoBehaviour
{
    Vector2 moveInput;
    Rigidbody2D myRigidBody;

    [SerializeField] float runSpeed = 10f;

    void Start()
    {
        myRigidBody = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        Run();
    }

    void OnMove(InputValue value)
    {
        moveInput = value.Get<Vector2>();
        Debug.Log(moveInput);
    }

    void Run()
    {
        Vector2 playerVelocity = new Vector2(moveInput.x * runSpeed, myRigidBody.velocity.y);
        myRigidBody.velocity = playerVelocity;
    }
}

Before I put in the code to limit the movement from going up and down (floating) that worked fine. I just can not get the player to move left and right.

1 Like

I don’t know if this will help either:

1 Like

Just for my sanity, do you have this line of code at the top of your script:

using UnityEngine.InputSystem;

Just because that’s a common mistake, also I believe in Tilevania Rick sets up an input system, id also make sure you have that set up as well.

Also, if you just want simple movement left and right without the input system here is a code sample I made:

using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
    [SerializeField] float moveSpeed = 5f;

    void Update()
    {
        float moveInput = Input.GetAxis("Horizontal");
        transform.position += new Vector3(moveInput * moveSpeed * Time.deltaTime, 0f, 0f);
    }
}

You can take note from that, however I recommend making sure your input system works, as I believe Rick has a video where he sets this up

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour

Yes, I triple checked the import statements. I also went back through the videos a few times to make sure I did not miss anything and even re-did a few steps. I will try your code to see it that at least gets my player moving.

1 Like

So I tried your code and my player is moving left and right with no issues. So now I have to see what I did wrong with the input system.

1 Like

Alright, that’s nice, hopefully I can find something to, I have tilevania on my old laptop, so maybe I can power up and compare a little more

A small bug that happens sometimes,
When you play the game and there is an option to have the game in focused, unfocused, and maximized, sometimes I’ve noticed that if the game isn’t in focus the input system is glitchy, just a thought, if you haven’t already id just try having the game in focused mode

1 Like

Just tried the focus mode with no luck. I might once again remove all input system elements and go back over the video(s) again. Not sure what I would have missed.

1 Like

Can you put a screenshot the input settings just in case there is something small going on there, I feel like something is going over my head, hopefully either of us can figure this out

player_input


1 Like

I have to walk away for a few but will keep beating my head on this.

1 Like

Wow, I looked through and you have the same stuff as Rick, must be something really small, I would now check to see if you have the proper version, however I’m not able to see what exactly is going wrong, maybe @Nina or @bixarrio or another problem solver would be able to see it, I’m still going to try to figure this out

Ran your code and used your settings (that I can see here) and everything works fine. Can you show what your player’s layout looks like? In the hierarchy.

2 Likes

player_layer
layers

So I did this in my code

 void OnMove(InputValue value)
    {
        moveInput = value.Get<Vector2>();
        Debug.Log(moveInput);
        Debug.Log("Velocity " + myRigidbody.velocity);
    }

When I click the up and down arrow keys I see:
velocity_up_down
(note, I get a -1.0) as well

But when I click the left and right arrow keys I only see:
velocity_right_left

So for some reason I am getting 0 velocity on the left and right arrows.

Please open the player input and send a screenshot of the left arrow (or right arrow) setup


I would like to see what the settings are

Also, why is this y-velocity 0.80? Is the player falling when you press the buttons?

velocity_up_down

Privacy & Terms