i have been trying so hard to get this to work and tried multiple methods. all i want to do is make the enemy always face towards the player on the x axis. heres what i got (game crashes when the enemy comes into view):

extends KinematicBody2D

signal is_colliding
signal is_not_colliding

const BULLET = preload("res://bullet.tscn")

var direction = 1
var shoot = false

onready var player = get_node("res://Player.gd")

func _ready():
	pass

func _physics_process(delta):
	
	$dealer.flip_h = direction.to_local(player.global_position).x < 0

There's a lot off with that code.

BULLET I think should be an "onready var" not "const" if you want to do anything with it. The player variable needs to be attached to the actual player node. not the script. So you have to use get_node() with the path to the player. For example, if the enemy and player are on the same level in the node hierarchy, then you can do "get_node("../Player")" assuming the player is named "Player". You should get familiar with how nodes work, as you will use them a lot.

Direction is a simple number (1), so I don't believe you can use member function on it. What you probably want to do is compare the enemy position to the player position. If they are under the same node (meaning they are in the same level together) then you can do this:

$dealer.flip_h = position.x < player.position.x

Or something like that, I'm just doing this in my head now.

thanks for the response. sorry about the mess, im still getting the hang of things so when i look up tutorials things occasionally become a blur of other peoples syntax and i have to tune it when i figure out what things are.

but thanks a lot for teaching me how to refer to nodes!

one last question without being too unrelated, how can i change the var direction = 1 relative to the players position?

nvm i got it

2 years later