Answer the question
In order to leave comments, you need to log in
Why doesn't the character jump right away?
There are times when the character jumps only after a few milliseconds, mostly when I poke the spacebar several times in a row
public float speed;
public float jumpForce;
public bool isGrounded;
public Transform transform;
public Rigidbody2D rigidbody2D;
void FixedUpdate()
{
if (Input.GetKey("d"))
{
transform.Translate(Vector2.right * Time.deltaTime * speed);
}
if (Input.GetKey("a"))
{
transform.Translate(Vector2.left * Time.deltaTime * speed);
}
if (Input.GetKeyDown("space") && isGrounded)
{
rigidbody2D.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
}
Answer the question
In order to leave comments, you need to log in
Physics is called in FixedUpdate. Input and stuff in Update. And you get it like this, you press the button, and during this time 2-3 frames skip and this is the delay
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question