Answer the question
In order to leave comments, you need to log in
Randomness of Unity physics?
When I press W the character jumps, but each time to a different height, how to fix it?
void Update()
{
Jump();
}
private void Jump()
{
if (Input.GetKeyDown(KeyCode.W))
{
var jumpVel = new Vector2(0, jumpForce * Time.deltaTime);
rb.velocity += jumpVel;
}
}
Answer the question
In order to leave comments, you need to log in
Basically just do it
void FixedUpdate()
{
Jump();
}
private void Jump()
{
if (Input.GetKeyDown(KeyCode.W))
{
var jumpVel = new Vector2(0, jumpForce);
rb.velocity += jumpVel;
}
}
1) Time.deltaTime
has a different meaning each time.
2)
var jumpVel = new Vector2(0, jumpForce * Time.deltaTime);
- you are trying to add speed instead of strength. rb.velocity += jumpVel;
- you add speed, so the sum can be at least zero. I recommend setting the speed hard: rb.velocity = jumpVel;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question