TileVania - Left / Right movement

Yes, the player was “floating” at the time

OK, ignore the velocity issue. Looks like I had my Debug in the wrong place.

updated_velocity_log

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

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

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

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

    }

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

    void Run()
    {
        myRigidbody.velocity = moveInput;
        Debug.Log("Velocity " + myRigidbody.velocity);
    }
}

The commented out lines did work as far as the player moving left to right. So that made me think my collisions and RidgidBody was setup correctly.

You’re still not showing me the controls I’m asking for. I would like to see either the Left Arrow or Right Arrow key setup. Please click on either one and send a screenie

The commented code does not use the new input system or the rigidbody.

My apologies.


Perfect, thanks.

Everything looks good. It’s a little bit of a mystery. Could you possibly zip the project up and upload it somewhere? Then I can look at it and try to figure out what the problem is. I’m sure it’s something simple, but it’s difficult to track down if I cannot ‘hold it in my hands and spin it around’…

Sure thing, let me get it zipped up and placed in a DropBox or public S3 bucket. I have come close to restarting the whole tutorial :frowning:

Here you go, let me know if the link works. 558MB file

Got it. Will take a quick look


Edit
I don’t have the same version of Unity installed. I’ll check it in an older version. If it doesn’t break I’ll install the correct version

1 Like

Thanks, I will be around for a few hours. I am a PHP Coder by trade but was really getting into this coarse when this blocked me. I have a feeling it is something small and I will be upset with myself for not catching it

OK, So far I have the same issue you have, so this is good.

One thing you should fix off the bat is that your player has two PlayerMovement components on it. Remove one. This doesn’t fix the problem, but you don’t want two on there.

I can fix the problem, but then this doesn’t match the course’s code. I’m checking the course and seeing if there is anything different between the course’s code and your code. The winner would be if your code matches the course’s

1 Like

Thank you so much for the help. If worse comes to worse I will restart this portion of the coarse with a new project. I did try and use the same version of unity that is in the coarse even though it is not the latest

OK, I have discovered the source of your discomfort;

On your player, your animator is set to apply root motion. Unset that and all will be well in the world.

image


Edit
Was a tough one to crack because it was the last place I’d think to check. I recreated the player without the animator and all was good. So, I figured it had to be something to do with the animator, perhaps Root Motion… And there it was

1 Like

You are a rock star! I wonder if I clicked it by accident or something. Thank you so much, I can move forward with the coarse as I have some ideas of my first game attempt!

It was a pleasure. I quite enjoyed the hunt… :wink:

1 Like

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

Privacy & Terms