-1
\$\begingroup\$

I'm trying to write a character controller for a free-moving camera. I don't want it influenced by physics at all (no gravity, no collisions, no inertia). I've managed to get great movement in the X and Z axes with an Input.GetAxis call, but I'm at a bit of a loss for how to move the camera in the Y direction. I figured I should be able to use the Jump axis, but it isn't responding. Here's what I've got in my character controller update function:

float walk = Input.GetAxis("Vertical") * speed;
float strafe = Input.GetAxis("Horizontal") * speed;
float jump = Input.GetAxis("Jump") * speed;
walk *= Time.deltaTime;
strafe *= Time.deltaTime;
jump *= Time.deltaTime;

transform.Translate(strafe, jump, walk);

This seems simple enough to me, but the Jump button (space) does nothing. Also, possibly related, possibly tangential: when I go into the InputManager, it won't let me change the keys set for controlling the Jump axis. I can manipulate the values for gravity and sensitivity, but when I change what keys control the Jump axis, it just defaults back to space for positive and blank for negative once I click away from the box.

\$\endgroup\$
  • 2
    \$\begingroup\$ "I figured I should be able to use the Jump axis" and yet your code read the "Horizontal" axis for computing Jump. That seems odd to me; is that a typo? \$\endgroup\$ – Josh Oct 19 '16 at 17:08
  • \$\begingroup\$ Yeah, that was a typo in the post, not the code. Sorry, should've just copied and pasted it. \$\endgroup\$ – ffollett Oct 19 '16 at 17:41
  • \$\begingroup\$ What values do you get for 'jump' when you press Space? Are they the same as when you aren't (so the axis isn't returning input)? Are they exceedingly smaller than you think they should be? \$\endgroup\$ – Josh Oct 19 '16 at 17:45
  • \$\begingroup\$ Ok, that's really embarrassing. Adding the line to print to the console made me realize I hadn't saved the script after adding the code for Y axis movement. It works just fine, other than the fact that the InputManager won't accept key values like 'LeftControl' and 'LeftShift'. I can change the keys to letters or numbers or 'space', but shift and control don't seem to be allowed? Am I using the wrong key codes for them? \$\endgroup\$ – ffollett Oct 19 '16 at 18:04
  • \$\begingroup\$ I don't actually use Unity so I can't say. Hopefully somebody else would have some idea. \$\endgroup\$ – Josh Oct 19 '16 at 18:06
0
\$\begingroup\$

If jump is configured to be a button then you should not be reading it as an axis but as a button.

Input.GetButtonDown("Jump")
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.