Moving using controller stick question (153306)

Trying to make it so -1 on the axis moves the player left and 1 moves the player right but my script doesnt appear to do anything. I was never able to figure out how to properly do controller support for my last game but I really want to include it this time because people seemed to really want it. I can do the buttons easy enough but I don’t understand the axis’s. What am I doing wrong?

			if(Input.GetButton("Horizontal"))
			{
				if(Input.GetAxisRaw("Horizontal") < 0)
				{
					Debug.Log("Left");
					vel.x = -walkSpeed;
				}
				if(Input.GetAxisRaw("Horizontal") > 0)
				{
					Debug.Log("Right");
					vel.x = walkSpeed;
				}
			}else
			{
				vel.x = 0;
			}

My project settings for “Horizontal” Are currently the default ones found when creating a new project in unity.

1 Answer

1

This would be simpler:

vel.x = Input.GetAxis("Horizontal");
if(vel.x != 0)
    vel.x = (vel.x < 0) ? -walkspeed : walkspeed

This assumes that the “Horizontal” axis is registered in Unity (Edit->Project Settings->Input), and of course that the result (vel.x) actually does something to your object

Still doesn't do anything. Maybe my project settings are wrong? Name : Horizontal Neg Button: Left Pos Button: Right Alt Neg: A Alt Pos: D Grav: 3 Dead: 0.001 Sens : 3 Snap : Yes Invert : No Type : Key or Mouse Button Axis : x axis Joy Num : Get Motion From all

Bumping because I'd really like to know whats wrong :(

Oh sorry. In first line of your code, write : using UnityEngine.SceneManagement; if you use C# or import UnityEngine.SceneManagement; if you use JS And change LoadScene(1) to SceneManager.LoadScene(1); I hope this work @JasperGlobal :)