- Home /
Problem is not reproducible or outdated
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;
}
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
Please Note : Moving the joystick does not trigger the Debug.Log
Answer by Jessespike · Nov 18, 2015 at 04:17 PM
Input.GetAxisRaw returns a number between -1 and 1, as mentioned in the documentation. Replace your code with this one line:
vel.x = walkSpeed * Input.GetAxisRaw("Horizontal") * Time.deltaTime;
The problem isn't that I don't move. The problem is that moving the joystick does nothing. Doesn't even activate the debug.log
Follow this Question
Related Questions
How to know if finger is on joystick if it is at horizontal & vertical zero 0 Answers
Controller Joystick Hold Delay Logic? 1 Answer
How to zero out the value of the joystick 0 Answers
Problems with joystick / controller axes being 1/-1 "way too often" 1 Answer
How do I create joystick controls with two fixed speeds? (3D) 1 Answer