Help with creating an enemy

I am creating a 2d top-down game, in it I created an enemy that goes towards the player, but for some reason the enemy flies up and hits the wall.

extends CharacterBody2D

var speed = 75


func _physics_process(delta):
	
	var direction = get_direction_to_player()
	velocity = speed * direction
	
	move_and_slide()
	
func get_direction_to_player():
	
	var player = get_tree().get_first_node_in_group("player") as Node2D
	
	if player != null:
		
		return (player.global_position - global_position).normalized()
		print(player.global_position, global_position)
	return Vector2.ZERO

If this is a topdown 2d game, what do you mean by up? negative y?

Anyway I do not see anything wrong with the code there. Is the enemy a child of something? Nodes inherit their position from their parent, so their position property is added to their parent’s own position property, so if the parent of the enemy is also moving, that could explain why it is not moving to the player.

If the enemy is moving the opposite direction of the player just make the direction negative like

velocity = speed * -direction