# The problem of jump force being added to knockback

<stable4.2>

### Question

<I made HURT state when player enter, knockback force will be added to player velocity. The problem is when player is jumping at the exact moment of being hit by enemy, player will be knockbacked way higher than expected. How can I prevent this?
Hurt State:

``````func enter(_msg := {}) -> void:
print("state hurt")
animation_player.play("PlayerHurt")
player.state_in_hurt = false
player.player_cannot_move = true
player.visible = true
player.can_shoot = false
player.velocity.y -= 300
if player.mark2D.scale.x ==1:
player.velocity.x = 250 * -1
else:
player.velocity.x = 250 * 1
player.calculate_health(player.scheduled_damage)
player.scheduled_damage = 0
pass

func physics_update(delta: float) -> void:
player.hitbox.set_deferred("disabled", true)
player.hurtbox.set_deferred("disabled", true)

player.velocity.x = lerpf(player.velocity.x, 0, 1.7 * delta)
player.velocity.y += player.get_gravity() * delta #gravity * delta #Gravity Calculation
player.move_and_slide()

if player.is_on_floor():
player._sprite_flash()
state_machine.transition_to("Idle")
if !is_zero_approx(player.get_input_direction()):
state_machine.transition_to("Run")
``````

Gravity Func:

``````func get_gravity() -> float:
if is_on_zero_gravity == true:
return 0.0
return jump_gravity if velocity.y < 0.0 else fall_gravity
``````

JUMP State:

``````func physics_update(delta: float) -> void:

player.sprite_flip()

if not is_zero_approx(player.get_input_direction()): #If Player is moving, calculate Player's velocity.x
player.velocity.x = lerpf(player.velocity.x, player.get_input_direction() * player.speed, player.acceleration * delta)
else: #If Player is not moving, Player's velocity.x = 0
player.velocity.x = lerpf(player.velocity.x, 0, player.air_friction * delta)

player.velocity.y += player.get_gravity() * delta #gravity * delta #Gravity Calculation
player.move_and_slide()

if player.velocity.y >= 0.0: #If Player's velocity.y is larger than zero, FALL STATE
if player.current_hang_time > player.max_hang_time:
state_machine.transition_to("Fall")
player.is_on_zero_gravity = false
else:
player.current_hang_time += delta
player.is_on_zero_gravity = true
if Input.is_action_just_pressed("jump") and player.air_jump==true:
state_machine.transition_to("AirJump")
player.air_jump = false
player.is_on_zero_gravity = false
return
``````

any idea?