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’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?
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)
}