Why is KinematicBody Compounding Gravity When Moving

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By trokal

I’ve been trying to use KinematicBody for character movement, but It’s behaving pretty unexpectedly. It’s compounding the force of gravity but only when in motion. here’s the entire script:

extends KinematicBody

var velocity = Vector3.ZERO
var max_acceleration = 100
var max_speed = 10
var max_ground_angle = 45
var movement_input = Vector2.ZERO
var snap_normal = Vector3.DOWN
var snap_distance = 0.2

func _process(delta):
	movement_input = Vector2(
		lerp(movement_input.x, 
		Input.get_action_strength("move_right") - 
		Input.get_action_strength("move_left"),
		0.4),
		lerp(movement_input.y,
		Input.get_action_strength("move_down") - 
		Input.get_action_strength("move_up"),
		0.4))
	
	movement_input.x = clamp(movement_input.x, -1, 1)
	movement_input.y = clamp(movement_input.y, -1, 1)
func _physics_process(delta):
	
	var gravityNormal = ProjectSettings.get_setting("physics/3d/default_gravity_vector")
	var gravityStep = (gravityNormal * ProjectSettings.get_setting("physics/3d/default_gravity")) * delta
	velocity += gravityStep
	
	var max_speed_change = max_acceleration * delta
	var desired_velocity = (Vector3(movement_input.x, 0, movement_input.y) * max_speed)
	
	velocity.x = desired_velocity.x
	velocity.z = desired_velocity.z

	velocity = move_and_slide(velocity, Vector3.UP, true, 4, deg2rad(max_ground_angle))

The ray is casting to the velocity vector while capsule is in motion.