- Home /
Problem with input
So I'm making a 2D controller script, and I've come up with a problem..
if(controller.velocity.y == 0)
{
speedY = 0;
}
if(Physics.Raycast(transform.position, -Vector3.up, .5f))
{
if(isJumping)
isJumping = false;
if(isAirborne)
isAirborne = false;
if(Input.GetKey("space"))
{
isJumping = true;
speedY = jumpHeight;
}
}
else
{
isAirborne = true;
}
if(controller.velocity.x == 0)
{
speedX = 0;
}
Not really sure if there's something wrong with the input, or that part of the code is just messed up.. the rest seems to work fine?
Thanks for any help at all
What's wrong? Just Input.Get$$anonymous$$ey("space") not working?
Yeah doesn't seem to respond at all. I've tried different keys, even setting up the axes differently and still no luck ? :S
Also, sorry I didn't explain the problem well, couldn't find the edit button (found it now)
Yeah tried with caps and without, I'm not completely sure what's wrong tbh, just doesn't seem to accept any input.
This is the first script I've written all by myself, so I guess I expected trouble, but this seems to be a really silly mistake and I cant figure it out :(
Your problem must be here:
Physics.Raycast(transform.position, -Vector3.up, .5f)
This only will return true, if exist a physic object right above and the distance < .5f of your character.
If you sure that you need to use this line, try to increase the distance.
Show us your jump script too.
Answer by Visual Programmer · Oct 05, 2013 at 12:22 AM
The best ways of handling input are either to add the input into the InputManager and call to the specified input or to directly call to the keycode of the key you are trying to press.
Here's some examples:
Input from input manager;
//requires an input labeled "Jump" in the InputManager
if(Input.GetButtonDown("Jump")){
Debug.Log("Jump");
}
//calls to the exact key that you want to press
if(Input.GetButtonDown(KeyCode.Space)){
Debug.Log("Jump")
}
Thanks for the replies!
So now I've added a debug log, input is deffo the problem as nothings happening.
I've tried it with $$anonymous$$eyCode.Space and then it just throws me an error, otherwise it saves and runs fine, but no actual jumping happens?