I noticed that when I tried to use Input.GetAxisRaw(“Vertical”) < 0 while at the same time holding down the jump and horizontal arrow key, the vertical arrow keys won’t register.
What I was trying to do was make it so when the character is jumping forward (Horizontal arrow key + space bar) if the down arrow key is pushed the character attacks straight down. Doesn’t work as the down arrow key won’t fire if the other two are begin pushed. The up arrow key is also finicky.
Here is my code (code is put in the object that spawns projectiles to fire at enemies) in case it’s a mistake I made scripting, otherwise it may be a unity bug. I printed each condition for the “Shooting straight down” part of the code and each condition passes except the Input.GetAxisRaw(“Vertical”) < 0, pushing the down arrow key does nothing. Works fine if I immediately let off of the space bar after jumping then try to shoot.
//~~~rest of code~~~
//Shooting straight up (keyboard only)
if(Input.GetAxisRaw("Vertical") > 0 canShoot == true shootTimer < Time.time)
{
transform.Rotate(0, 90, 0);
heightMod = 1;
Shoot();
canShoot = false; //I will have to expand on this for diffrent weapons
shootTimer = Time.time+0.4;
}
//Shooting straight down (keyboard only) ... groundedShoot is if the player is grounded
if(groundedShoot == false Input.GetAxisRaw("Vertical") < 0 canShoot == true shootTimer < Time.time)
{
transform.Rotate(0, 90, 0);
heightMod = -1;
Shoot();
canShoot = false; //I will have to expand on this for diffrent weapons
shootTimer = Time.time+0.4;
}
//Player not pushing button, set canshoot true...
if(canShoot == false !Input.GetKey("d") !Input.GetKey("e") !Input.GetKey("c")
!Input.GetButton("Fire1") Input.GetAxisRaw("Vertical") == 0 shootTimer < Time.time)
{
heightMod = 0;
canShoot = true;
}
} //End Update Function
function Shoot () {
audio.PlayOneShot(soundLaserB);
//Fire a projectile
var projectile : Rigidbody = Instantiate(shot, transform.position+Vector3(0,aimAdjustY,0), transform.rotation); //Quaternion.Euler(0,0,0) <- no change
//print(transform.position+Vector3(0,aimAdjustY,0));
projectile.velocity = transform.TransformDirection(Vector3(1,heightMod,0) * speed);
projectile.GetComponent(ProjectileCollision_Script).timeToDie = range;
projectile.GetComponent(ProjectileCollision_Script).damage = dmg;
//transform.rotation = Quaternion.identity;
transform.rotation = parent.transform.rotation;
//transform.localPosition = Vector3.zero; <- Just to have it
//BroadcastMessage("ShootSmall");
}
Yes, I debugged Input.GetAxisRaw(“Vertical”), it returns -1 when clicking down arrow as it should except for when I am holding another arrow key and space also, then it returns 0.
If you mean shoudl is possibly be a <= rather than < … no, it needs to be <. There are only three values with this: 1, 0 and -1. 0 means it’s not being pushed or both up and down are being pushed (canceling each other out).
If you need to be able to detect buttons individually then you need to either treat them as buttons rather than axes, or treat them as separate axes and combine them only when you actually want combined input.
But I’m not using the Vertical axis (Y axis) more than once at the same time. The down arrow key should be the only button using the vertical axis during the combo. I don’t see how pushing the jump button and holding it should in any way eliminate the down axis from firing. I call this a bug.
Oh right, I see what you mean. There aren’t any gravity or dampening or other settings on the axis that could be messing with it or causing delays?
The other thing I’d check is whether your keyboard supports that combination of keys elsewhere, as there can be limits on how many keys can be pressed at once and reported correctly. But the limit on anything vaguely new is usually at least 3 keys, so I think it’s unlikely.
No, haven’t concluded for certain it’s a bug yet. I’m tired. I’ll mess with it more tomorrow a bit and see what I come up with.
Also, if anyone would like to try and reproduce this themselves feel free to try. Just use space as the jump and the horizontal arrow keys as moving right to left and use down key to shoot down (while in the air). Reproduce the problem by running and jumping, holding the move forward key and the jump key down and then press the down arrow key and confirm it does not fire. All three keys must be held down simultaneously at some point to reproduce.
If I get you right you are saying that when you press multiple buttons at once( more or equal 3 ) than your Input isn’t recognized ?! If so than it is probably a limitation of your Keyboard.
like element_wsc already suggested, i am pretty sure its not a bug, but a common keyboard issue. Keyboards cant register all keys pressed same time. Try out different key combo, or different keyboard and you’ll see.
Yeah, that’s just because of how I cut the code from my script to post here. My bad, I’ll fix it in my original post.
When I used a letter key instead of the down arrow it worked fine. It’s possible that it’s a keyboard issue. To effectively troubleshoot it I suppose I can make the same combo in game-maker to rule out if it’s the keyboard or not.
Indeed. Its more like physical feature with your keyboard. Same results come out no matter what software you use, unless there is restriction by that software Keep in mind the key combination you find out working, might or might not work with different keyboard. Therefore you should let the user choose what keys to use.
Yes, I confirmed with Game Maker Studio that the key combination I was trying to use in Unity doesn’t work in that either. It is in fact a keyboard limitation. I guess the human race isn’t advanced enough to make keyboards without such basic limitations.
As for worrying about others keyboards, what a pain in the ass. Now I’m looking at setting up a key binding system for the keyboard which was supposed to be a fallback set of controls for players that don’t have USB controllers on hand. I expected to have to set up binding for controllers, but now for keyboards, only because somebodies keyboard may not work correctly. It makes the controls for the game nebulous at best.
Oh well, case closed, wasn’t programming error or a unity bug. Just the result of crap keyboard manufacturers.