I am making a platformer game and implemented jumping, but I have an issue,when I multiply the JUMP VALUE with Time.deltaTime , the value is slightly different every time.
Is it possible to make the player jump with same value every time the player jumps? Here is my code.
void Update () {
if(gameManager.paused) return;
isPressed = false;
if (Input.GetKey(KeyCode.LeftArrow) || isBtnLeft)
{
isPressed = true;
xSpeed -= (SPEED_STEP*Time.deltaTime);
xSpeed = xSpeed<-MAX_X_SPEED ?-MAX_X_SPEED:xSpeed;
}
if (Input.GetKey(KeyCode.RightArrow) || isBtnRight)
{
isPressed = true;
xSpeed += (SPEED_STEP*Time.deltaTime);
xSpeed = xSpeed>MAX_X_SPEED ?MAX_X_SPEED:xSpeed;
}
if (Input.GetKeyDown(KeyCode.UpArrow) || isBtnJump){
if(!isJumping){
isBtnJump = false;
isJumping = true;
squish(0.5f,1.4f);
float currentJumpSpeed = (jumpSpeed*Time.deltaTime);
currentJumpSpeed = currentJumpSpeed>MAX_JUMP_SPEED ? MAX_JUMP_SPEED:currentJumpSpeed;
ySpeed += jumpSpeed;
}
}else
ySpeed -=(gravity*Time.deltaTime);
ySpeed = ySpeed<MAX_FALL_SPEED ? MAX_FALL_SPEED:ySpeed;
if (Mathf.Abs(xSpeed)<1&&! isPressed) {
xSpeed=0;
}
collisionY();
collisionX();
xSpeed *=hFriction;
}
}
What if i dont multiple the jumpSpeed with delta time?
Thanks