#W key not working
1 messages · Page 1 of 1 (latest)
If I Wright literally Debug.Log(Input.GetKeyDown(“w”)) in a void update loop with nothing else, it will randomly return true but when I’m still pressing w sometimes returns false
If I swap it for a different key it works
If I swap out the keyboard nothing changes too
Input.GetKeyDown will only return true for one frame when you start pressing the key. If you want the value to stay true as long as the key is being held, use Input.GetKey.
Also for the sake of performance, GetKeyDown should be used with the KeyCode enum as a parameter, rather than strings.
The jump script is suppose to do that and is suppose to return it for 1 frame. It was working before I got it on the pc. I have made some progress though, I found out it works if I use an if statement instead. I am sure it doesn’t work with debug because I did a test where I changed my max FPS to 1 so I could check my frames and it never showed true unless apart from those few frames, but now I understand it may well be a separate issue as I am using an if statement in the code.
Every time I randomly jump it is executed from line 344, is grounded is permanently true so it is not that, the coroutine cyotetime has been tested and is not changing IsJump to false, there is no reason for it to not jump occasionally so I’m just very confused
These are the jump coroutines
do not send photos of your screen. and neither images of code. please.
Use codeblocks to send code in a message!
To make a codeblock, surround your code with ```
To use C# syntax highlighting add cs after the three back ticks.
For example:
```cs
Console.WriteLine("Hello World");
```
Produces:
Console.WriteLine("Hello World");
To send lengthy code, paste it into https://paste.myst.rs/ and send the link of the paste into chat.
Oh wait I think I know the problem
Does adding a ! Before a condition infer that the answer would be opposite
Because that’s what I thought but I’m not sure
yes, an exclamation mark in front of a boolean inverts it.
Ok that’s wierd
So if I say if (IsGrounded) {Debug.Log(“grounded”) it displays in air but if I put an exclamation mark before it it still displays in just air
And yes my isgrounded works perfectly
You do realize that you are starting a new CoyoteTime coroutine every frame as long as IsGrounded is true, and each of those runs independently and potentially overrides the current state of IsGrounded?
This may or may not become an issue.
I do realise that but the thing is I have this same project on my laptop and it works perfectly but on my pc, not so much
Ok idk now the debugs are working perfectly now and I changed nothing
Could this be one of those very rare times it’s not user error?
Are you saying that Unity is at fault for the behaviour you observe?
If so, I'd doubt it.
I just built this pc and nothing is wrong with it so far but it could be a problem with it no idea how though, or maybe their was some corruption when installing the project into a usb stick. I am too in doubt that unity is at fault
Did you follow a tutorial for the coyote time, or did you implement it on your own?
It is my own but it did work
But for some reason I’m the coyote time it returns true on the if statement
Which is odd because if I debug weather grounded is true before, it will say yes
Which is why I was considering that the issue is because i did !IsGrounded
Frankly, I would just do something like this for Coyote Time: ```cs
private float coyoteTime;
private bool groundState;
[SerializeField] private float coyoteDuration = 0.5f;
public bool IsGrounded { get; private set; }
private void Update ()
{
UpdateGroundState();
UpdateIsGrounded();
}
private void UpdateGroundState()
{
// do some kind of ground check and set "groundState".
}
private void UpdateIsGrounded ()
{
if (groundState) // if we are actually grounded, reset coyote time
{
coyoteTime = coyoteDuration;
}
else // if we are not actually grounded
{
coyoteTime -= Time.deltaTime; // decrease coyote time
}
IsGrounded = groundState || coyoteTime > 0f; // set IsGrounded to true as long as we are actually grounded, or coyoteTime is greater than 0.
}```no coroutines needed.
What would the explanation for it working on my laptop but not my@pc be tho?
Because i feel like it’s not a coroutine problem for that reason
Perhaps there it runs on a different framerate, and that changes the behaviour 🤷♂️