- Home /
Jumping Issue on Different Computers
I'm having a bit of trouble getting my jump mechanic working correctly on different machines. Works fine on my PC, Mac and laptop, but some testers say the jump height on their computer is much too small. Which sounds like a Time.deltaTime issue.
You can try it for yourself here: Press C to shoot/enter the level
Basic jump mechanic: Longer you hold the jump button (up to .2 seconds), the higher the jump.
Here's how I calculate the movement (In Update):
if(_canMove)
{
_horizontalVelocity = Input.GetAxis("Horizontal");
_horizontalVelocity = _horizontalVelocity * _speed * Time.deltaTime;
}
Jumping logic (ApplyJumping called in Update)(_jumpMultiplier is a float I use to control the general height of the jump):
void ApplyJumping()
{
if(Input.GetButtonDown("Jump"))
{
_isJumpPressed = true;
if(_canJump)
{
StartCoroutine(JumpPrep());
}
}
if(Input.GetButtonUp("Jump"))
{
_isJumpPressed = false;
}
if(_isJumping)
{
_jumpPower -= _gravity * Time.deltaTime;
_verticalVelocity = _jumpPower;
}
if(_controller.isGrounded)
{
_canJump = true;
_hasReachedApex = false;
if(_isJumping || _isFalling)
{
if(_isJumpPressed)
{
if(_canJump)
{
StartCoroutine(JumpPrep());
}
}
}
_isFalling = false;
_isJumping = false;
_jumpPower = 0;
_verticalVelocity = 0;
}
}
IEnumerator JumpPrep()
{
float count = 0;
_isPreparingJump = true;
_animationController.PlayPrepareToJump();
_canMove = false;
_canJump = false;
_isFalling = false;
while(_isJumpPressed && count <= _maximumJumpPrepSeconds)
{
count += Time.deltaTime;
yield return null;
}
_canMove = true;
_isJumping = true;
_isPreparingJump = false;
_jumpPower = _jumpMultiplier * Mathf.Min(count, _maximumJumpPrepSeconds);
}
Finally, this is how I put the two together for the final movement velocity (In Update):
if(_canMove)
{
_movementVelocity = new Vector3(_horizontalVelocity, _verticalVelocity, 0f);
}
else
{
_movementVelocity = new Vector3(0f, _verticalVelocity, 0f);
}
_controller.Move(_movementVelocity);
Your answer
Follow this Question
Related Questions
Why can't I properly jump? 2 Answers
attached.Rigidbody isn't working with a ChactacterController? -1 Answers
can anyone help me to smooth the jump? 0 Answers
Differentiate jump and moving up slope 0 Answers
Why isn't my character jumping?? 1 Answer