- Home /
Moving using controller stick question
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.
Answer by ian_sorbello · Nov 18, 2015 at 03:46 AM
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.
$$anonymous$$aybe 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 : $$anonymous$$ey or $$anonymous$$ouse Button Axis : x axis Joy Num : Get $$anonymous$$otion From all
You need to add another axis registered in the input manager for the joystick.... I think.
If in doubt, bring your movement script over to a clean fresh project and see if that works, then if it does, you know the inputs got mangled up somehow.
Can you expand on that? I don't usually muck about with inputs. What settings would I apply to the new input.
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Damaging Enemies 1 Answer
sprite character rotation 0 Answers