RESOLVED Can anyone please explain this potential scaling issue that is causing movement...

My movement and animations worked great when using the PC keyboard but when I changed it to allow a touchscreen D-pad too (for mobile) the animations still work but the player doesn’t move (unless on PC in which case move works but animations now don’t).

I have found this link c# - I animated my 2D game but my character doesn't move - Stack Overflow where someone was coincidentally following the brackeys tutorial on animation that I did and he ran into pretty much the same issue.

"I’ve been following Brackeys tutorials to make a 2D game and right now I’m on animation. The animation plays he attacks, the sprite flips both directions, etc… but still stuck in the same spot. I’ve watched and rewatched the tutorial and can’t figure it out.

Before adding animation everything worked perfectly. He moved across the screen, he jumped, etc… So i know that him not moving is directly tied to trying to animating"

Only difference is I ran into the problem when following the Brackeys D-Pad tutorial after I already completed the movement and animation.

Someone answered saying “I was scaling the main object for some of my animations. To fix it I went in and removed any scaling of the main container object and instead scaled the internal objects individually”…

But being a beginner all I know about “scaling” is the ability to change it in the transform box on the x/y/z axis’ but all my game objects scales are set to 1 so I don’t understand what he means and can’t figure it out?

Any suggestions much appreciated!

Movement code if anyone kind enough to look! Thanks!

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

public class moveCharacter : MonoBehaviour
{

    public GameObject Player;
    public GameObject Player2;
    public GameObject otherObject;
    float horizontalMove = 0f;
    float verticalMove = 0f;
    public Animator animator;
    float speed = 7f;
    public Joystick joystick;

    private void Start()
    {
        Player2.gameObject.SetActive(false);
        otherObject.GetComponent<CameraController2>().enabled = false;
    }

    void Update()
    {
        //Uncomment the below line for PC controls (and comment out the line after that)
        //horizontalMove = Input.GetAxisRaw("Horizontal") * speed;
        horizontalMove = joystick.Horizontal * speed;
       
        animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
        var move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        transform.position += move * speed * Time.deltaTime;
        {

            if (horizontalMove > 0)
            {

               
                Player2.gameObject.SetActive(false);
                Player.gameObject.SetActive(true);
                transform.rotation = Quaternion.Euler(-28.38f, 180f, 0);
                otherObject.GetComponent<CameraController2>().enabled = false;
                otherObject.GetComponent<CameraController>().enabled = true;
                Player2.transform.position = Player.transform.position;

            }

            else if (horizontalMove < 0)
            {

               
                Player2.gameObject.SetActive(false);
                Player.gameObject.SetActive(true);
                transform.rotation = Quaternion.Euler(28.38f, 0, 0);
                otherObject.GetComponent<CameraController2>().enabled = false;
                otherObject.GetComponent<CameraController>().enabled = true;
                Player2.transform.position = Player.transform.position;

            }
        }

    }
    void LateUpdate()
    {
        //verticalMove = Input.GetAxisRaw("Vertical") * speed;
        verticalMove = joystick.Vertical * speed;
       
        //animator.SetFloat("Speed", Mathf.Abs(verticalMove));
        var move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
        transform.position += move * speed * Time.deltaTime;
        {

            if (verticalMove > 0)
            {

                Player.gameObject.SetActive(false);
                Player2.gameObject.SetActive(true);
                otherObject.GetComponent<CameraController>().enabled = false;
                otherObject.GetComponent<CameraController2>().enabled = true;
                Player.transform.position = Player2.transform.position;


            }

            else if (verticalMove < 0)
            {

                Player.gameObject.SetActive(false);
                Player2.gameObject.SetActive(true);
                otherObject.GetComponent<CameraController>().enabled = false;
                otherObject.GetComponent<CameraController2>().enabled = true;
                Player.transform.position = Player2.transform.position;

            }
        }

    }
}

Problem was this line:

var move = new Vector3(Input.GetAxis(“Horizontal”), 0, Input.GetAxis(“Vertical”)); transform.position += move * speed * Time.deltaTime;

If you are on a touch screen these axis calls can not be heard.

Thanks to someone on another forum this nailed it:

//Establish the variable as essentially empty. Don't use empty var, personally I hate undefined variables.
Vector3 move = Vector3.zero;
//Listen if the input system is using a keyboard or controller
move =  new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
//If there is no keyboard or controller then move will still be a vector3.zero the next line will listen to your joypad inputs
// I adde da if not null conditional so if your publish for PC with  no joy stick this line will not throw errors
if (joystick != null)
{
    move = new Vector3( joystick.Horizontal * speed, 0,  joystick.Vertical * speed)
}